#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int M = 1e2 + 5;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const long long lINF = 0x3f3f3f3f3f3f3f3fLL;
const int sINF = 0xcfcfcfcf;
long long a, b, sum, l, mi, ans;
int main() {
  scanf("%lld%lld", &a, &b);
  sum = a + b;
  mi = sum;
  for (long long l = 1; l <= sqrt(1.0 * sum); l++) {
    if (l <= sqrt(1.0 * a) && a % l == 0) mi = min(mi, a / l);
    if (l <= sqrt(1.0 * b) && b % l == 0) mi = min(mi, b / l);
    if (sum % l == 0 && sum / l >= mi) {
      ans = (l + sum / l) * 2;
    }
  }
  printf("%lld\n", ans);
}
