#include <bits/stdc++.h>
using namespace std;
bool pan(long long x, long long y, long long n, long long m) {
  for (long long i = x; i >= 1; --i) {
    if ((n % i == 0 && n / i <= y) || (m % i == 0 && m / i <= y)) return true;
  }
  return false;
}
int main() {
  long long n, m;
  while (scanf("%I64d %I64d", &n, &m) != EOF) {
    long long num = n + m, ans = (num + 1) * 2;
    for (long long i = sqrt(num); i >= 2; --i) {
      if (num % i == 0) {
        if (pan(i, num / i, n, m)) {
          ans = (i + num / i) * 2;
          break;
        }
      }
    }
    printf("%I64d\n", ans);
  }
}
