#include <bits/stdc++.h>
using namespace std;
vector<long long> f(long long x) {
  vector<long long> a;
  for (int k = 1; 1LL * k * k <= x; ++k) {
    if (x % k) continue;
    a.push_back(k);
  }
  return a;
}
signed main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long a, b, ans = LLONG_MAX;
  cin >> a >> b;
  auto x = f(a + b);
  auto y = f(a);
  auto z = f(b);
  sort(y.begin(), y.end());
  sort(z.begin(), z.end());
  for (auto w : x) {
    auto h = (a + b) / w;
    int k = upper_bound(y.begin(), y.end(), w) - y.begin() - 1;
    if (k >= 0 && a / y[k] <= h)
      ans = min(ans, 2 * (h + w));
    else {
      k = upper_bound(z.begin(), z.end(), w) - z.begin() - 1;
      if (k >= 0 && b / z[k] <= h) ans = min(ans, 2 * (h + w));
    }
  }
  cout << ans << '\n';
  return 0;
}
