#include <bits/stdc++.h>
using namespace std;
vector<long long> divisors(long long a) {
  vector<long long> vec;
  long long sqrta = sqrt(a) + 1e-6;
  for (int i = 1; i <= sqrta; i++) {
    if (a % i == 0) vec.push_back(i);
  }
  return vec;
}
int main() {
  long long a, b, c;
  cin >> a >> b;
  c = a + b;
  auto divc = divisors(c);
  auto diva = divisors(a);
  auto divb = divisors(b);
  long long ans = 1e16;
  for (auto W : divc) {
    long long H = c / W;
    for (auto w : diva) {
      long long h = a / w;
      if (W - w + 1 > 0 and H - h + 1 > 0) {
        ans = min(ans, W + W + H + H);
      }
    }
    for (auto w : divb) {
      long long h = b / w;
      if (W - w + 1 > 0 and H - h + 1 > 0) {
        ans = min(ans, W + W + H + H);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
