#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > diva, divb;
set<long long> a1, b1;
long long a, b;
signed main() {
  cin >> a >> b;
  for (long long i = 1; i <= sqrt(a); i++)
    if (a % i == 0) diva.push_back({i, a / i});
  for (long long i = 1; i <= sqrt(b); i++)
    if (b % i == 0) divb.push_back({i, b / i});
  long long x = a + b, lasta = 0, lastb = 0;
  long long ans = 1e18;
  for (long long i = 1; i <= sqrt(x); i++) {
    if (x % i == 0) {
      for (; lasta < diva.size() && diva[lasta].first <= i; lasta++)
        a1.insert(diva[lasta].second);
      for (; lastb < divb.size() && divb[lastb].first <= i; lastb++)
        b1.insert(divb[lastb].second);
      auto it1 = a1.upper_bound(x / i);
      auto it2 = b1.upper_bound(x / i);
      if (it1 != a1.begin() || it2 != b1.begin()) {
        ans = min(ans, 2 * (i + (x / i)));
      }
    }
  }
  cout << ans;
  return 0;
}
