#include <iostream>
#include <algorithm>
#include <vector>
#include <assert.h>
using namespace std;
long long a, b;
long long S, P;
long long sqrt (long long s) {
long long d = 0, c = (long long)(1e8), res = -1;
while (d <= c) {
long long g = (d + c) / 2;
if (g * g <= s) {
res = g;
d = g + 1;
} else c = g - 1;
}
return res;
}
int main() {
cin >> a >> b;
S = a + b;
long long root = sqrt(S);
long long root_of_a = sqrt(a);
long long root_of_b = sqrt(b);
P = (long long)(1e18);
vector < long long > diva;
vector < long long > divb;
for (long long i = 1; i <= root_of_a; i++)
if (a % i == 0)
diva.push_back(i);
for (long long i = 1; i <= root_of_b; i++)
if (b % i == 0)
divb.push_back(i);
for (long long i = 1; i <= root; i++) {
if (S % i == 0) {
auto it = lower_bound(diva.begin(), diva.end(), i);
if(it != diva.end()) {
if(*it > i && it != diva.begin()) it--;
if(*it <= i && a / *it <= S/i)
P = min(P, 1LL * 2*(i + S/i));
}
else {
it--;
if (a / *it <= S / i)
P = min(P, 1LL * 2*(i + S/i));
}
it = lower_bound(divb.begin(), divb.end(), i);
if(it != divb.end()) {
if(*it > i && it != divb.begin()) it--;
if(*it <= i && b / *it <= S/i)
P = min(P, 1LL * 2*(i + S/i));
}
else {
it--;
if (b / *it <= S / i)
P = min(P, 1LL * 2*(i + S/i));
}
}
}
cout << P << '\n';
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YXNzZXJ0Lmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpsb25nIGxvbmcgYSwgYjsKbG9uZyBsb25nIFMsIFA7Cgpsb25nIGxvbmcgc3FydCAobG9uZyBsb25nIHMpIHsKCWxvbmcgbG9uZyBkID0gMCwgYyA9IChsb25nIGxvbmcpKDFlOCksIHJlcyA9IC0xOwoJd2hpbGUgKGQgPD0gYykgewoJCWxvbmcgbG9uZyBnID0gKGQgKyBjKSAvIDI7CgkJaWYgKG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