#include <bits/stdc++.h>
using namespace std;
unordered_map<long long int, long long int> funmap[2];
int main() {
  long long int a, b;
  scanf("%lld%lld", &a, &b);
  long long int result = 1e17;
  long long int prev_a = -1, prev_b = -1;
  for (long long int i = 1LL; i * i <= a + b; i++) {
    if (a % i == 0) prev_a = i;
    if (b % i == 0) prev_b = i;
    if ((a + b) % i == 0) {
      if (prev_a != -1)
        if (a / prev_a <= (a + b) / i)
          result = min(result, 2 * i + 2 * ((a + b) / i));
      if (prev_b != -1)
        if (b / prev_b <= (a + b) / i)
          result = min(result, 2 * i + 2 * ((a + b) / i));
    }
  }
  printf("%lld\n", result);
}
