#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long a, b;
  cin >> a >> b;
  long long t = a + b;
  long long x = 1, y = 1;
  long long ans = 2 + 2 * t;
  for (long long i = 1; i * i <= t; ++i) {
    if (a % i == 0) x = i;
    if (b % i == 0) y = i;
    if (t % i == 0 && (a / x <= t / i || b / y <= t / i)) {
      ans = min(ans, 2 * i + 2 * (t / i));
    }
  }
  cout << ans;
}
