#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, sum = 0, minn, minw = 1e18;
  cin >> a >> b;
  sum = a + b;
  minn = (a + b) * 2 + 2;
  for (long long i = 1; i <= sqrt(sum) + 0.5; i++) {
    if (a % i == 0) minw = min(minw, a / i);
    if (b % i == 0) minw = min(minw, b / i);
    if (sum % i == 0 && minw <= sum / i)
      minn = min(minn, i * 2 + (sum / i) * 2);
  }
  cout << minn << endl;
  return 0;
}
