#include <bits/stdc++.h>
using namespace std;
long long a, b;
long long S, P;
long long sqrt(long long s) {
  long long d = 0, c = (long long)(1e8), res = -1;
  while (d <= c) {
    long long g = (d + c) / 2;
    if (g * g <= s) {
      res = g;
      d = g + 1;
    } else
      c = g - 1;
  }
  return res;
}
int main() {
  cin >> a >> b;
  S = a + b;
  long long root = sqrt(S);
  long long root_of_a = sqrt(a);
  long long root_of_b = sqrt(b);
  P = (long long)(1e18);
  vector<long long> diva;
  vector<long long> divb;
  for (long long i = 1; i <= root_of_a; i++)
    if (a % i == 0) diva.push_back(i);
  for (long long i = 1; i <= root_of_b; i++)
    if (b % i == 0) divb.push_back(i);
  for (long long i = 1; i <= root; i++) {
    if (S % i == 0) {
      auto it = lower_bound(diva.begin(), diva.end(), i);
      if (it != diva.end()) {
        if (*it > i && it != diva.begin()) it--;
        if (*it <= i && a / *it <= S / i) P = min(P, 1LL * 2 * (i + S / i));
      } else {
        it--;
        if (a / *it <= S / i) P = min(P, 1LL * 2 * (i + S / i));
      }
      it = lower_bound(divb.begin(), divb.end(), i);
      if (it != divb.end()) {
        if (*it > i && it != divb.begin()) it--;
        if (*it <= i && b / *it <= S / i) P = min(P, 1LL * 2 * (i + S / i));
      } else {
        it--;
        if (b / *it <= S / i) P = min(P, 1LL * 2 * (i + S / i));
      }
    }
  }
  cout << P << '\n';
  return 0;
}
