#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e6;
const long long Inf = 1LL << 60;
struct node {
  long long x, y;
} siga[MaxN + 5], sigb[MaxN + 5];
int main() {
  long long a, b, ans, n, cur, flag, cnta, cntb, da, db;
  while (~scanf("%I64d %I64d", &a, &b)) {
    ans = 2LL + 2LL * a + 2LL * b;
    if (a > b) {
      cur = a;
      a = b;
      b = cur;
    }
    n = a + b;
    cnta = 0LL;
    cntb = 0LL;
    for (long long i = 1LL; i * i <= b; i++) {
      cur = b / i;
      if (cur * i == b) {
        sigb[++cntb].x = i;
        sigb[cntb].y = cur;
      }
      cur = a / i;
      if (cur * i != a) continue;
      siga[++cnta].x = i;
      siga[cnta].y = cur;
    }
    da = 1LL;
    db = 1LL;
    for (long long i = 1LL; i * i <= n; i++) {
      cur = n / i;
      if (cur * i != n) continue;
      flag = 0;
      while (da + 1 <= cnta && siga[da + 1].x <= i) da++;
      if (siga[da].x <= i && siga[da].y <= cur) flag = 1;
      while (db + 1 <= cntb && sigb[db + 1].x <= i) db++;
      if (sigb[db].x <= i && sigb[db].y <= cur) flag = 1;
      if (flag) ans = min(ans, 2LL * i + 2LL * cur);
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
