#include <bits/stdc++.h>
using namespace std;
const long long Mod = 7 + 1e9;
const long long MAX = 5 + 1e5;
long long a, b, c;
vector<long long> da, db, dc;
vector<long long> fact(long long k, vector<long long>& ret);
long long ans(long long m, vector<long long>& dm);
int main() {
  cin >> a >> b;
  c = a + b;
  fact(a, da);
  fact(b, db);
  fact(c, dc);
  cout << min(ans(a, da), ans(b, db)) << endl;
  return 0;
}
vector<long long> fact(long long k, vector<long long>& ret) {
  long long sq = sqrt(k) + 0.001;
  if (sq * sq == k) ret.push_back(sq);
  for (long long i = 1; i * i < k; i++)
    if (k % i == 0) ret.push_back(k / i);
  sort(ret.begin(), ret.end());
  return ret;
}
long long ans(long long m, vector<long long>& dm) {
  for (long long cc : dc) {
    auto it = upper_bound(dm.begin(), dm.end(), cc);
    if (it != dm.begin()) {
      it--;
      if (m / *it <= c / cc) return 2 * (cc + c / cc);
    }
  }
}
