#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int _max = 1e6 + 10;
typedef int ints[_max];
long long solve(long long a, long long b) {
  vector<long long> viLen;
  for (long long i = 1; i * i <= a; i++)
    if (a % i == 0) viLen.push_back(i);
  int j = 0;
  long long a_b = a + b;
  long long ans = (a + b + 1) << 1;
  for (long long i = 1; i * i <= a_b; i++)
    if (a_b % i == 0) {
      while (j + 1 < viLen.size() && viLen[j + 1] <= i) j++;
      if (a / viLen[j] <= a_b / i) ans = min(ans, (i + a_b / i) << 1);
    }
  return ans;
}
int main() {
  long long a, b;
  scanf("%I64d%I64d", &a, &b);
  printf("%I64d", min(solve(a, b), solve(b, a)));
  return 0;
}
