#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const unsigned gen_seed =
    std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);
int main() {
  long long a, b, x;
  cin >> a >> b;
  x = (long long)sqrt(a + b + 0.1);
  long long ab = a + b;
  long long la = x, lb = x;
  while (x > 0) {
    if (ab % x == 0) {
      long long y = ab / x;
      long long x0 = min(x, la);
      while (x0 > 0) {
        if (a % x0 == 0) {
          if (a / x0 > y) {
            la = x0;
            break;
          } else {
            cout << 2 * (x + y);
            return 0;
          }
        } else
          x0--;
      }
      x0 = min(x, lb);
      while (x0 > 0) {
        if (b % x0 == 0) {
          if (b / x0 > y) {
            lb = x0;
            break;
          } else {
            cout << 2 * (x + y);
            return 0;
          }
        } else
          x0--;
      }
      x = ab / min(a / la, b / lb);
    } else
      x--;
  }
  return 0;
}
