#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
const long double pi = acos(-1);
vector<long long> f(long long x) {
  vector<long long> v;
  for (long long d = 1; d * d <= x; d++) {
    if (x % d == 0) {
      v.push_back(d);
      if (d * d < x) {
        v.push_back(x / d);
      }
    }
  }
  sort(v.begin(), v.end());
  return v;
}
long long a, b;
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(15);
  cout << fixed;
  cout.tie(0);
  cin.tie(0);
  cin >> a >> b;
  vector<long long> va = f(a);
  vector<long long> vb = f(b);
  vector<vector<long long> > vs;
  vs.push_back(va);
  vs.push_back(vb);
  vector<long long> vab = f(a + b);
  long long ans = INFL;
  for (long long d1 : vab) {
    long long d2 = (a + b) / d1;
    int i = upper_bound(va.begin(), va.end(), d1) - va.begin() - 1;
    if (i >= 0) {
      long long da1 = va[i];
      long long da2 = a / da1;
      if (da1 <= d1 && da2 <= d2) {
        ans = min(ans, 2 * (d1 + d2));
      }
    }
    i = upper_bound(vb.begin(), vb.end(), d1) - vb.begin() - 1;
    if (i >= 0) {
      long long db1 = vb[i];
      long long db2 = b / db1;
      if (db1 <= d1 && db2 <= d2) {
        ans = min(ans, 2 * (d1 + d2));
      }
    }
  }
  cout << ans << '\n';
}
