#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + 5;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int t, n, m, k;
long long a, b;
long long vala[maxn], valb[maxn], valab[maxn];
int main() {
  while (~scanf("%lld%lld", &a, &b)) {
    long long s = (a + b);
    int cnta, cntb, cntab;
    cnta = cntb = cntab = 0;
    long long ans = 4e14;
    for (long long i = 1; i * i <= a; ++i) {
      if (a % i == 0) vala[cnta++] = i;
    }
    for (long long i = 1; i * i <= b; ++i) {
      if (b % i == 0) valb[cntb++] = i;
    }
    for (long long i = 1; i * i <= s; ++i) {
      if (s % i == 0) valab[cntab++] = i;
    }
    for (int i = 0; i < cntab; ++i) {
      int flag = 0;
      for (int j = 0; j < cnta; ++j) {
        if (vala[j] > valab[i]) break;
        if (a / vala[j] <= s / valab[i]) {
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        for (int j = 0; j < cntb; ++j) {
          if (valb[j] > valab[i]) break;
          if (b / valb[j] <= s / valab[i]) {
            flag = 1;
            break;
          }
        }
      }
      if (flag) {
        ans = min(ans, 2ll * (valab[i] + s / valab[i]));
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
