#include <iostream>
#include <algorithm>
using namespace std;
long long a, b;
long long gcd(long long x, long long y)
{
if(x % y == 0)
return x;
else
return gcd(y, x % y) + x / y * y;
}
int main(void)
{
cin >> a >> b;
if(a < b)
swap(a, b);
cout << gcd(a, b) * 4;
return 0;
}