#include <bits/stdc++.h>
using namespace std;
bool pos(long long w, long long h, vector<long long>& v) {
  long long num = v[0] * v.back();
  int lo = 0, hi = v.size() - 1;
  if (v[hi] <= w)
    lo = hi;
  else {
    while (lo + 1 < hi) {
      long long mid = (lo + hi) / 2;
      if (v[mid] <= w)
        lo = mid;
      else
        hi = mid;
    }
  }
  return num / v[lo] <= h;
}
int main() {
  long long a, b;
  scanf("%lld %lld", &a, &b);
  long long res = (1LL << 62);
  vector<long long> v1, v2;
  for (long long i = 1; i * i <= a; i++)
    if (a % i == 0) {
      v1.push_back(i);
      if (i * i != a) v1.push_back(a / i);
    }
  for (long long i = 1; i * i <= b; i++)
    if (b % i == 0) {
      v2.push_back(i);
      if (i * i != b) v2.push_back(b / i);
    }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  for (long long i = 1; i * i <= a + b; i++)
    if ((a + b) % i == 0) {
      long long w = i, h = (a + b) / i;
      if (pos(w, h, v1) || pos(w, h, v2) || pos(h, w, v1) || pos(h, w, v2)) {
        if (res > w + h) res = w + h;
      }
    }
  printf("%lld\n", res << 1);
  return 0;
}
