#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> cnta, cntb;
vector<int>::iterator xa, xb;
ll a, b, S;
int sS, i;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b;
  S = a + b;
  sS = sqrt(S);
  for (i = 1; i <= sS; ++i) {
    if (a % i == 0) cnta.emplace_back(i);
    if (b % i == 0) cntb.emplace_back(i);
  }
  for (i = sS; i >= 1; --i) {
    if (S % i) continue;
    xa = lower_bound(cnta.begin(), cnta.end(), (int)ceil(1.0 * i * a / S));
    xb = lower_bound(cntb.begin(), cntb.end(), (int)ceil(1.0 * i * b / S));
    if ((xa != cnta.end() && *xa <= i) || (xb != cntb.end() && *xb <= i)) {
      cout << 2 * (i + S / i);
      return 0;
    }
  }
  return 0;
}
