#include <bits/stdc++.h>
using namespace std;
long long a, b, c;
vector<long long> da, db, dc;
vector<long long> f(long long x) {
  vector<long long> d;
  for (long long i = 1; i * i <= x; ++i) {
    if (x % i) continue;
    d.push_back(i);
    d.push_back(x / i);
  }
  sort(d.begin(), d.end());
  d.resize(unique(d.begin(), d.end()) - d.begin());
  return d;
}
bool ok(long long n, long long m, vector<long long>& d, long long val) {
  long long x = d[lower_bound(d.begin(), d.end(), n + 1) - d.begin() - 1];
  long long y = val / x;
  return y <= m;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> a >> b;
  c = a + b;
  da = f(a);
  db = f(b);
  dc = f(c);
  long long res = 1e18;
  for (int i = 0; i < dc.size(); ++i) {
    long long n = dc[i];
    long long m = c / n;
    if (n > m) break;
    if (ok(n, m, da, a) || ok(n, m, db, b)) res = min(res, 2 * (n + m));
  }
  cout << res;
  return 0;
}
