#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 5;
const int base = 3e5 + 1;
long long a, b, c;
vector<long long> dA, dB;
bool Check(long long x) {
  int u = upper_bound(dA.begin(), dA.end(), x) - dA.begin() - 1;
  int v = upper_bound(dB.begin(), dB.end(), x) - dB.begin() - 1;
  u = dA[u];
  v = dB[v];
  if (a / u <= c / x) return 1;
  if (b / v <= c / x) return 1;
  return 0;
}
bool Ok(long long x) {
  long long y = c / x;
  if (a % x == 0 || b % x == 0 || a % y == 0 || b % y == 0) return 1;
  if (Check(x) || Check(y)) return 1;
  return 0;
}
void Prepare(vector<long long> &d, long long x) {
  for (long long i = 1; i * i <= x; ++i)
    if (x % i == 0) {
      d.push_back(i);
      if (i * i != x) d.push_back(x / i);
    }
  sort(d.begin(), d.end());
}
void Solve() {
  cin >> a >> b;
  long long res = 1e18 + 7;
  Prepare(dA, a);
  Prepare(dB, b);
  c = (a + b);
  for (long long i = 1; i * i <= c; ++i) {
    if (c % i == 0 && Ok(i)) {
      res = min(res, 2 * (i + c / i));
    }
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  if (fopen("running"
            ".inp",
            "r")) {
    freopen(
        "running"
        ".inp",
        "r", stdin);
    freopen(
        "running"
        ".out",
        "w", stdout);
  }
  int test_case = 1;
  while (test_case--) {
    Solve();
  }
  return 0;
}
