#include <bits/stdc++.h>
using std::map;
using std::pair;
using std::unordered_map;
using std::vector;
vector<long long> adiv;
vector<long long> bdiv;
vector<long long> cdiv;
void factor(long long n, vector<long long>& vec) {
  vec.clear();
  vec.push_back(1);
  for (long long i = 2; n > 1; ++i) {
    if (i > n || i * i > n) i = n;
    int r = 0;
    while (n % i == 0) {
      ++r;
      n /= i;
    }
    if (r) {
      long long p = i;
      long long pp = p;
      int sz = vec.size();
      for (int i = 1; i <= r; ++i) {
        for (int j = 0; j < sz; ++j) {
          vec.push_back(vec[j] * pp);
        }
        if (i < r) pp *= p;
      }
    }
  }
}
inline long long readll() {
  long long n;
  scanf("%lld", &n);
  return n;
}
int main() {
  long long a = readll();
  long long b = readll();
  long long c = a + b;
  factor(a, adiv);
  factor(b, bdiv);
  factor(c, cdiv);
  sort(adiv.begin(), adiv.end());
  sort(bdiv.begin(), bdiv.end());
  sort(cdiv.begin(), cdiv.end());
  int ia = adiv.size() / 2;
  int ib = bdiv.size() / 2;
  long long res = c + c + 1 + 1;
  for (int ic = cdiv.size() / 2; ic < int(cdiv.size()); ++ic) {
    long long la = adiv[ia];
    long long lb = bdiv[ib];
    long long lc = cdiv[ic];
    while (ia + 1 < int(adiv.size()) && adiv[ia + 1] <= lc) la = adiv[++ia];
    while (ib + 1 < int(bdiv.size()) && bdiv[ib + 1] <= lc) lb = bdiv[++ib];
    if (la <= lc && a / la <= c / lc) {
      res = (lc + c / lc) * 2;
      break;
    }
    if (lb <= lc && b / lb <= c / lc) {
      res = (lc + c / lc) * 2;
      break;
    }
  }
  printf("%lld\n", res);
  return 0;
}
