#include <bits/stdc++.h>
using namespace std;
const long long mos = 0x7FFFFFFFLL;
const long long nmos = 0x80000000LL;
const int inf = 0x3f3f3f3f;
const long long inff = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
template <typename T>
inline T read(T& x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x = f ? -x : x;
}
long long a, b, sum;
bool check(long long x, long long y) {
  for (long long i = x; i >= 1; i--) {
    if (a % i == 0 && a / i <= y) return true;
    if (b % i == 0 && b / i <= y) return true;
  }
  return false;
}
int main() {
  cin >> a >> b;
  sum = a + b;
  long long ans = inff;
  for (long long i = 1ll; i * i <= sum; i++) {
    if (sum % i == 0) {
      long long x = i, y = sum / i;
      if (check(x, y)) {
        ans = min(ans, 2ll * (x + y));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
