#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long a, b;
  cin >> a >> b;
  long long s = a + b;
  long long ans = s;
  long long r = 1;
  for (long long d = 1; d * d <= s; d++) {
    if (s % d) continue;
    while (r <= d && (a % r || a / r > s / d)) r++;
    if (r <= d && !(a % r) && a / r <= s / d) {
      ans = d + s / d;
    }
  }
  r = 1;
  for (long long d = 1; d * d <= s; d++) {
    if (s % d) continue;
    while (r <= d && (b % r || b / r > s / d)) r++;
    if (r <= d && !(b % r) && b / r <= s / d) {
      ans = min(ans, d + s / d);
    }
  }
  cout << ans * 2 << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << setprecision(12);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
