#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll inf = 1e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll a, b;
  cin >> a >> b;
  ll c = a + b;
  auto add = [](ll x, map<ll, ll, greater<ll>>& m) {
    for (ll i = 1; i * i <= x; ++i) {
      if (x % i != 0) {
        continue;
      }
      if (!m.count(x / i)) {
        m[x / i] = i;
      } else {
        m[x / i] = min(m[x / i], i);
      }
    }
  };
  map<ll, ll, greater<ll>> m[2];
  add(a, m[0]);
  add(b, m[1]);
  ll best = 2 * (c + 1);
  for (ll i = 1; i * i <= c; ++i) {
    if (c % i != 0) {
      continue;
    }
    ll j = c / i;
    for (int k : {0, 1}) {
      auto it = m[k].lower_bound(j);
      if (it != m[k].end() && it->second <= i) {
        best = min(best, 2 * (i + j));
      }
    }
  }
  cout << best << '\n';
  return 0;
}
