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