#include <bits/stdc++.h>
using namespace std;
vector<long long> aa, bb;
long long bin(vector<long long> &a, long long v) {
  int l = 0, r = a.size(), m;
  if (v >= a[r - 1]) return a[r - 1];
  for (; l < r - 1;) {
    m = (l + r) >> 1;
    if (a[m] > v)
      r = m;
    else
      l = m;
  }
  return a[l];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  long long a, b, c, first, second;
  cin >> a >> b;
  for (long long i = 1; i * i <= a; i++)
    if (!(a % i)) aa.push_back(i);
  for (long long i = 1; i * i <= b; i++)
    if (!(b % i)) bb.push_back(i);
  c = a + b;
  long long ans = 8e18;
  for (int i = sqrt(c); i >= 1; i--)
    if (!(c % i)) {
      first = bin(aa, i);
      second = bin(bb, i);
      if ((first <= i && a / first <= c / i) ||
          (second <= i && b / second <= c / i))
        ans = min(2 * i + 2 * c / i, ans);
    }
  cout << ans;
  return 0;
}
