#include <bits/stdc++.h>
using namespace std;
long long a, b, ans = 1e18;
int main() {
  cin >> a >> b;
  for (long long m = 1, xa = 1, xb = 1; m * m <= a + b; ++m) {
    if (a % m == 0) xa = m;
    if (b % m == 0) xb = m;
    if ((a + b) % m == 0) {
      long long n = (a + b) / m;
      if (n >= a / xa || n >= b / xb) ans = min(ans, 2 * (n + m));
    }
  }
  cout << ans << endl;
  return 0;
}
