#include <bits/stdc++.h>
using namespace std;
long long peri = 1000000000000000000LL;
void solve(long long sum, long long a) {
  long long sumdiv = 1, adiv = 1;
  long long sumrem = sum, arem = a;
  for (long long i = 1; i * i <= sum; i++) {
    if (sum % i == 0) {
      sumdiv = i;
      sumrem = sum / i;
    }
    if (a % i == 0 && a / i >= i) {
      adiv = i;
      arem = a / i;
    }
    if (sumdiv >= adiv && sumrem >= arem)
      peri = min(peri, 2 * (sumdiv + sumrem));
  }
}
int main() {
  ios::sync_with_stdio(0);
  long long t = 1;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long sum = a + b;
    solve(sum, a);
    solve(sum, b);
    cout << peri << endl;
  }
  return 0;
}
