#include <bits/stdc++.h>
using namespace std;
const int N = 10001000;
const int mod = 1000000007;
long long xx[N], yy[N], xcnt, ycnt;
long long x, y, z, mmin;
int ffindx(int val) {
  int left = 1, right = xcnt, mid;
  int ans = -1;
  while (left < right) {
    mid = (left + right + 1) >> 1;
    if (xx[mid] <= val) {
      ans = mid;
      left = mid;
    } else
      right = mid - 1;
  }
  if (xx[left] <= val) return left;
  return ans;
}
int ffindy(int val) {
  int left = 1, right = ycnt, mid;
  int ans = -1;
  while (left < right) {
    mid = (left + right + 1) >> 1;
    if (yy[mid] <= val) {
      ans = mid;
      left = mid;
    } else
      right = mid - 1;
  }
  if (yy[left] <= val) return left;
  return ans;
}
int main() {
  int s, t;
  scanf("%lld%lld", &x, &y);
  for (long long i = 1; i <= (long long)sqrt(x); i++) {
    if (x % i == 0) {
      xx[++xcnt] = i;
      xx[++xcnt] = x / i;
    }
  }
  for (long long i = 1; i <= (long long)sqrt(y); i++) {
    if (y % i == 0) {
      yy[++ycnt] = i;
      yy[++ycnt] = y / i;
    }
  }
  sort(xx + 1, xx + xcnt + 1);
  sort(yy + 1, yy + ycnt + 1);
  z = x + y;
  for (long long i = (long long)sqrt(z); i >= 1; i--) {
    if (z % i == 0) {
      s = ffindx(i);
      t = ffindy(i);
      if ((s != -1 && (x / xx[s]) <= z / i) ||
          (t != -1 && (y / yy[t]) <= z / i)) {
        printf("%lld\n", 2 * i + 2 * (z / i));
        return 0;
      }
    }
  }
  return 0;
}
