#include <bits/stdc++.h>
using namespace std;
const long long size = 1e6 + 7;
const long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long a, b;
  cin >> a >> b;
  vector<long long> v1, v2;
  for (long long i = 1; i <= (long long)sqrt(a); i++) {
    if (a % i == 0) v1.push_back(i);
  }
  for (long long i = 1; i <= (long long)sqrt(b); i++) {
    if (b % i == 0) v2.push_back(i);
  }
  long long ans = 1e18;
  long long tot = a + b;
  for (long long i = 1; i <= (long long)sqrt(a + b); i++) {
    if (tot % i == 0) {
      long long x = i;
      long long y = tot / i;
      long long ps = upper_bound(v1.begin(), v1.end(), x) - v1.begin();
      ps--;
      if (ps >= 0 and v1[ps] <= x) {
        if (a / v1[ps] <= y) {
          ans = min(ans, 2 * (x + y));
          continue;
        }
      }
      ps = upper_bound(v2.begin(), v2.end(), x) - v2.begin();
      ps--;
      if (ps >= 0 and v2[ps] <= x) {
        if (b / v2[ps] <= y) ans = min(ans, 2 * (x + y));
        continue;
      }
    }
  }
  cout << ans << endl;
}
