#include <bits/stdc++.h>
using namespace std;
long long a[3], ans;
vector<long long> divs[3];
void fac(long long idx, long long x) {
  for (long long i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      if (i * i < x) {
        divs[idx].push_back(x / i);
      }
      divs[idx].push_back(i);
    }
  }
  sort(divs[idx].begin(), divs[idx].end());
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> a[1] >> a[2];
  fac(0, a[1] + a[2]);
  fac(1, a[1]);
  fac(2, a[2]);
  ans = 1e18;
  for (long long j = 1; j < 3; ++j) {
    for (auto i : divs[0]) {
      long long bgr = max(i, (a[1] + a[2]) / i);
      auto ub = upper_bound(divs[j].begin(), divs[j].end(), bgr);
      if (ub == divs[j].begin()) {
        continue;
      }
      --ub;
      if ((a[1] + a[2]) / bgr >= a[j] / (*ub)) {
        ans = min(ans, (bgr) + (a[1] + a[2]) / bgr);
      }
    }
  }
  ans *= 2;
  cout << ans;
}
