#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
long long diva[maxn];
long long divc[maxn];
int main() {
  long long a, b;
  scanf("%lld%lld", &a, &b);
  long long c = a + b;
  long long r = sqrt(c);
  int cnt1 = 0, cnt2 = 0;
  for (long long i = 1; i <= r; i++) {
    if (c % i == 0) {
      divc[cnt1++] = i;
    }
  }
  long long ans = c * 2 + 2;
  r = sqrt(a);
  for (long long i = 1; i <= r; i++) {
    if (a % i == 0) {
      diva[cnt2++] = i;
    }
  }
  long long la = 0, lc = 0;
  while (lc < cnt1) {
    for (; la < cnt2; la++) {
      if (diva[la] > divc[lc]) {
        la--;
        break;
      }
    }
    if (la == cnt2) la--;
    if (a / diva[la] <= c / divc[lc]) {
      ans = min(ans, 2 * (divc[lc] + c / divc[lc]));
    }
    lc++;
  }
  cnt2 = 0;
  r = sqrt(b);
  for (long long i = 1; i <= r; i++) {
    if (b % i == 0) {
      diva[cnt2++] = i;
    }
  }
  la = 0, lc = 0;
  while (lc < cnt1) {
    for (; la < cnt2; la++) {
      if (diva[la] > divc[lc]) {
        la--;
        break;
      }
    }
    if (la == cnt2) la--;
    if (b / diva[la] <= c / divc[lc]) {
      ans = min(ans, 2 * (divc[lc] + c / divc[lc]));
    }
    lc++;
  }
  printf("%lld\n", ans);
}
