#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 1e18;
const int MOD = 998244353;
const int alphabet = 26;
const int MAXINT = 2e5 + 1;
long long MIN(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long solve(long long a, long long b) {
  vector<int> div;
  for (int i = 1; i < sqrt(b) + 1; i++)
    if (b % i == 0) div.push_back(i);
  int j = 0;
  long long peri = INFLL;
  long long num = a + b;
  for (int i = 1; i < sqrt(num) + 1; i++)
    if (num % i == 0) {
      while (j + 1 < div.size() && div[j + 1] <= i) j++;
      if (num / i >= b / div[j]) peri = MIN(peri, 2 * i + 2 * num / i);
    }
  return peri;
}
int main() {
  long long a, b;
  scanf("%lld", &a), scanf("%lld", &b);
  printf("%lld\n", MIN(solve(a, b), solve(b, a)));
}
