#include <bits/stdc++.h>
using std::vector;
int main() {
  long long a, b, ans = 1000000000000000000LL;
  scanf("%I64d%I64d", &a, &b);
  long long c = a + b;
  vector<long long> dela, delb;
  vector<long long>::iterator it;
  for (long long i = 1LL; i * i <= a; i++) {
    if (!(a % i)) {
      dela.push_back(i);
    }
  }
  for (long long i = 1LL; i * i <= b; i++) {
    if (!(b % i)) {
      delb.push_back(i);
    }
  }
  for (long long x = 1LL; x * x <= c; x++) {
    if (!(c % x)) {
      long long y = c / x;
      bool good = false;
      for (it = dela.begin(); it != dela.end(); it++) {
        if (*it <= x && (a / *it) <= y) {
          good = true;
          break;
        }
      }
      if (!good) {
        for (it = delb.begin(); it != delb.end(); it++) {
          if (*it <= x && (b / *it) <= y) {
            good = true;
            break;
          }
        }
      }
      if (good && (x + y < ans)) {
        ans = x + y;
      }
    }
  }
  printf("%I64d\n", ans * 2LL);
  return 0;
}
