#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  cin >> a >> b;
  long long n = a + b;
  set<long long> can;
  long long res = 1e18;
  for (long long d = 1; d * d <= n; ++d) {
    if (a % d == 0) can.insert(a / d);
    if (b % d == 0) can.insert(b / d);
    if (n % d == 0) {
      long long h = d;
      long long w = n / d;
      if (*can.begin() <= w) res = min(res, h + w + h + w);
    }
  }
  cout << res << endl;
  return 0;
}
