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