#include <bits/stdc++.h>
using namespace std;
long long ans;
vector<long long> all, aa, bb;
int main() {
  aa.clear();
  bb.clear();
  all.clear();
  long long a, b;
  cin >> a >> b;
  ans = 2 * (a + b + 1);
  for (long long i = 1; i * i <= (a + b); i++)
    if ((a + b) % i == 0) all.push_back(i);
  for (long long i = 1; i * i <= a; i++)
    if (a % i == 0) aa.push_back(i);
  for (long long i = 1; i * i <= b; i++)
    if (b % i == 0) bb.push_back(i);
  int now1 = 0, now2 = 0;
  while (now1 < aa.size() && now2 < all.size()) {
    if (aa[now1] <= all[now2] && (a / aa[now1]) <= (a + b) / (all[now2])) {
      ans = min(ans, 2 * (all[now2] + (a + b) / all[now2]));
      now2++;
    } else if (aa[now1] > all[now2])
      now2++;
    else
      now1++;
  }
  now1 = 0, now2 = 0;
  while (now1 < bb.size() && now2 < all.size()) {
    if (bb[now1] <= all[now2] && (b / bb[now1]) <= (a + b) / (all[now2])) {
      ans = min(ans, 2 * (all[now2] + (a + b) / all[now2]));
      now2++;
    } else if (bb[now1] > all[now2])
      now2++;
    else
      now1++;
  }
  cout << ans << endl;
  return 0;
}
