#include <bits/stdc++.h>
using namespace std;
long long perimeterR(long long, long long);
int main() {
  long long a, b;
  scanf("%I64d %I64d", &a, &b);
  printf("%I64d\n", min(perimeterR(a, b), perimeterR(b, a)));
  return 0;
}
long long perimeterR(long long a, long long b) {
  vector<long long> div;
  for (long long i = 1; i * i <= a; i++) {
    if (a % i == 0) div.push_back(i);
  }
  long long ret = -1;
  long long sum = a + b;
  for (long long i = 1; i * i <= sum; i++) {
    if (sum % i == 0) {
      for (int j = 0; j < div.size(); j++) {
        long long aDiv = div[j];
        if (aDiv <= i && a / aDiv <= sum / i) {
          ret = (i + sum / i) * 2;
          break;
        }
      }
    }
  }
  return ret;
}
