#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > d, c;
void get(long long x) {
  for (long long i = 1LL; i * i <= x; i++) {
    if (x % i) continue;
    if (x / i == i)
      d.push_back({i, i});
    else
      d.push_back({x / i, i});
  }
}
void get2(long long x) {
  for (long long i = 1LL; i * i <= x; i++) {
    if (x % i) continue;
    if (x / i == i)
      c.push_back({i, i});
    else
      c.push_back({x / i, i});
  }
}
int busca(long long x) {
  int ini = 0, fim = c.size() - 1, ans = -1;
  while (ini <= fim) {
    int mid = (ini + fim) >> 1;
    if (c[mid].first <= x)
      ans = mid, ini = mid + 1;
    else
      fim = mid - 1;
  }
  return ans;
}
int main(void) {
  long long a, b;
  cin >> a >> b;
  get(a + b);
  get2(a);
  sort(c.begin(), c.end());
  long long ans = 1e18 + 10;
  for (int i = 0; i < d.size(); i++) {
    int x = busca(d[i].first);
    if (x == -1) continue;
    if (c[x].second <= d[i].second)
      ans = min(ans, 2LL * (d[i].first + d[i].second));
  }
  c.clear();
  get2(b);
  sort(c.begin(), c.end());
  for (int i = 0; i < d.size(); i++) {
    int x = busca(d[i].first);
    if (x == -1) continue;
    if (c[x].second <= d[i].second)
      ans = min(ans, 2LL * (d[i].first + d[i].second));
  }
  cout << ans << "\n";
}
