#include <bits/stdc++.h>
using namespace std;
long long a, b;
void solve() {
  scanf("%lld%lld", &a, &b);
  long long c = a + b;
  long long minp = 1000000000LL * 1000000000;
  vector<long long> ra;
  for (long long i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      ra.push_back(i);
      if (i * i != a) ra.push_back(a / i);
    }
  }
  sort(ra.begin(), ra.end());
  vector<long long> rc;
  for (long long i = 1; i * i <= c; i++) {
    if (c % i == 0) {
      rc.push_back(i);
      if (i * i != c) rc.push_back(c / i);
    }
  }
  sort(rc.begin(), rc.end());
  int i = 0;
  for (int j = 0; j < rc.size();) {
    if (rc[j] >= ra[i] && c / rc[j] >= a / ra[i]) {
      long long p = rc[j] + c / rc[j];
      p *= 2;
      if (p < minp) minp = p;
      j++;
    } else if (i + 1 < ra.size() && rc[j] >= ra[i + 1])
      i++;
    else
      j++;
  }
  ra.clear();
  swap(a, b);
  for (long long i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      ra.push_back(i);
      if (i * i != a) ra.push_back(a / i);
    }
  }
  sort(ra.begin(), ra.end());
  i = 0;
  for (int j = 0; j < rc.size();) {
    if (rc[j] >= ra[i] && c / rc[j] >= a / ra[i]) {
      long long p = rc[j] + c / rc[j];
      p *= 2;
      if (p < minp) minp = p;
      j++;
    } else if (i + 1 < ra.size() && rc[j] >= ra[i + 1])
      i++;
    else
      j++;
  }
  cout << minp << endl;
}
int main() {
  solve();
  return 0;
}
