#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 1e6 + 50;
const long long INF = 2e18;
long long qpower(long long x, long long p, long long M = MOD) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = ans * x % M;
    p >>= 1;
    x = x * x % M;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  long long x;
  while (b) {
    x = a % b;
    a = b;
    b = x;
  }
  return a;
}
long long modp(long long x, long long p = MOD) { return (x % p + p) % p; }
long long addp(long long x, long long y, long long p = MOD) {
  return x + y >= p ? x + y - p : x + y;
}
long long subp(long long x, long long y, long long p = MOD) {
  return x - y < 0 ? x - y + p : x - y;
}
long long fcta[N];
int tota = 0;
void getFactor(long long x) {
  for (int i = 1; (long long)i * i <= x; ++i) {
    if (x % i == 0) fcta[tota++] = i;
  }
}
long long fctb[N];
int totb = 0;
void getFactor2(long long x) {
  for (int i = 1; (long long)i * i <= x; ++i) {
    if (x % i == 0) fctb[totb++] = i;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  long long a, b;
  cin >> a >> b;
  getFactor(a);
  getFactor2(b);
  int posa, posb;
  posa = posb = 0;
  long long ans = INF;
  for (long long i = 1; (long long)i * i <= a + b; ++i) {
    if ((a + b) % i == 0) {
      long long n = i, m = (a + b) / i;
      while (posa < tota && fcta[posa] <= n && a / fcta[posa] > m) posa++;
      while (posb < totb && fctb[posb] <= n && b / fctb[posb] > m) posb++;
      if ((posa < tota && fcta[posa] <= n && a / fcta[posa] <= m) ||
          (posb < totb && fctb[posb] <= n && b / fctb[posb] <= m))
        ans = min(ans, 2 * n + 2 * m);
    }
  }
  cout << ans << endl;
}
