#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  long long a, b;
  long long Min = 10000000000000007;
  long long ans = 10000000000000007;
  long long i;
  cin >> a >> b;
  n = a + b;
  for (i = 1; i <= sqrt(n); i++) {
    if (a % i == 0) Min = min(Min, a / i);
    if (b % i == 0) Min = min(Min, b / i);
    if (n % i) continue;
    long long x = i, y = n / i;
    if (Min <= y) ans = min(ans, 2 * (x + y));
  }
  cout << ans << endl;
  return 0;
}
