#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
long long a, b, tot, ans = LLONG_MAX;
vector<long long> adiv, bdiv;
bool bin(long long val, vector<long long> v, long long i) {
  int l = 0, r = (int)v.size() - 1;
  while (l < r) {
    int mid = (l + r + 1) / 2;
    if (v[mid] <= i) {
      if (val / v[mid] <= tot / i)
        l = mid;
      else
        l = mid + 1;
    } else
      r = mid - 1;
  }
  return v[l] <= i && val / v[l] <= tot / i;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> a >> b;
  for (long long i = 1; i * i <= a; ++i)
    if (a % i == 0) {
      adiv.push_back(i);
      if (i * i != a) adiv.push_back(a / i);
    }
  for (long long i = 1; i * i <= b; ++i)
    if (b % i == 0) {
      bdiv.push_back(i);
      if (i * i != b) bdiv.push_back(b / i);
    }
  sort(adiv.begin(), adiv.end());
  sort(bdiv.begin(), bdiv.end());
  tot = a + b;
  for (long long i = 1; i * i <= tot; ++i)
    if (tot % i == 0) {
      if (bin(a, adiv, i) || bin(b, bdiv, i) || bin(a, adiv, tot / i) ||
          bin(b, bdiv, tot / i))
        ans = 2 * (i + tot / i);
    }
  cout << ans << "\n";
  return 0;
}
