#include <bits/stdc++.h>
using namespace std;
long long li[10000005];
long long li2[10000005];
int main() {
  long long a, b;
  scanf("%lld%lld", &a, &b);
  int uj, uj2;
  for (long long i = 1; i * i <= b; i++) {
    if (b % i == 0) {
      li[i] = b / i;
    } else {
      li[i] = li[i - 1];
    }
    uj = i;
  }
  for (long long i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      li2[i] = a / i;
    } else {
      li2[i] = li2[i - 1];
    }
    uj2 = i;
  }
  a += b;
  long long ans = 1e17;
  for (long long i = 1; i * i <= a; i++) {
    if (a % i != 0) continue;
    if ((li[min((int)i, uj)] > a / i) && (li2[min((int)i, uj2)] > a / i))
      continue;
    long long tmp = a / i;
    tmp += i;
    tmp *= 2LL;
    ans = min(ans, tmp);
  }
  printf("%lld\n", ans);
  return 0;
}
