#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
void solve() {
  long long a, b;
  cin >> a >> b;
  long long c = a + b;
  long long ans = LLONG_MAX;
  vector<pair<long long, long long>> av;
  for (long long i = 1; 1LL * i * i <= a; i++) {
    if (a % i) continue;
    av.push_back(make_pair(i, a / i));
    av.push_back(make_pair(a / i, i));
  }
  vector<pair<long long, long long>> bv;
  for (long long i = 1; 1LL * i * i <= b; i++) {
    if (b % i) continue;
    bv.push_back(make_pair(i, b / i));
    bv.push_back(make_pair(b / i, i));
  }
  sort((av).begin(), (av).end());
  sort((bv).begin(), (bv).end());
  for (long long i = 1; 1LL * i * i <= c; i++) {
    if (c % i) continue;
    long long x = i;
    long long y = c / i;
    {
      auto it = upper_bound((av).begin(), (av).end(), make_pair(x, LLONG_MAX));
      if (it != av.begin()) {
        it--;
        if (it->second <= y) ans = min(ans, x + y);
      }
    }
    {
      auto it = upper_bound((av).begin(), (av).end(), make_pair(y, LLONG_MAX));
      if (it != av.begin()) {
        it--;
        if (it->second <= x) ans = min(ans, x + y);
      }
    }
    {
      auto it = upper_bound((bv).begin(), (bv).end(), make_pair(x, LLONG_MAX));
      if (it != bv.begin()) {
        it--;
        if (it->second <= y) ans = min(ans, x + y);
      }
    }
    {
      auto it = upper_bound((bv).begin(), (bv).end(), make_pair(y, LLONG_MAX));
      if (it != bv.begin()) {
        it--;
        if (it->second <= x) ans = min(ans, x + y);
      }
    }
  }
  cout << ans * 2 << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
