#include <bits/stdc++.h>
using namespace std;
const long long inf = 0xFFFFFFFFFFFFFFFL;
clock_t time_p = clock();
void time() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
void divisors(long long n, vector<long long>& factors) {
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / i == i)
        factors.push_back(i);
      else {
        factors.push_back(min(i, n / i));
      }
    }
  }
}
int main() {
  long long a, b;
  cin >> a >> b;
  vector<long long> fac1;
  divisors(a + b, fac1);
  sort(fac1.begin(), fac1.end());
  vector<long long> facA;
  divisors(a, facA);
  sort(facA.begin(), facA.end());
  vector<long long> facB;
  divisors(b, facB);
  sort(facB.begin(), facB.end());
  bool case1 = false;
  long long ans1 = inf;
  long long ans2 = inf;
  for (long long i = (long long)fac1.size() - 1; i >= 0; i--) {
    long long f1 = (a + b) / fac1[i];
    long long f2 = fac1[i];
    auto it = upper_bound(facA.begin(), facA.end(), f2);
    it--;
    long long x = *it;
    long long y = a / x;
    if (f1 >= y) {
      ans1 = 2 * (f1 + f2);
      break;
    }
  }
  for (long long i = (long long)fac1.size() - 1; i >= 0; i--) {
    long long f1 = (a + b) / fac1[i];
    long long f2 = fac1[i];
    auto it = upper_bound(facB.begin(), facB.end(), f2);
    it--;
    long long x = *it;
    long long y = b / x;
    if (f1 >= y) {
      ans2 = 2 * (f1 + f2);
      break;
    }
  }
  cout << min(ans1, ans2) << "\n";
  time();
  return 0;
}
