#include <bits/stdc++.h>
using namespace std;
vector<long long int> func(long long int n) {
  vector<long long int> v;
  for (long long int i = 1; i * i <= n; i++)
    if (n % i == 0) v.push_back(i);
  return v;
}
bool check(long long int x, long long int y, long long int n,
           vector<long long int> v) {
  auto it = upper_bound(v.begin(), v.end(), y);
  if (it == v.end() || *it > y) it = prev(it, 1);
  long long int t = ceil((n / (x * 1.0)) * y);
  auto ut = lower_bound(v.begin(), v.end(), t);
  if ((ut - it) > 0)
    return false;
  else
    return true;
}
int main() {
  long long int a, b, lo = pow(10, 18);
  cin >> a >> b;
  vector<long long int> g = func(a + b), x = func(a), y = func(b);
  for (long long int i = 0; i < g.size(); i++)
    if (check(a + b, g[i], a, x) || check(a + b, g[i], b, y))
      lo = min(lo, g[i] + (a + b) / g[i]);
  cout << 2 * lo;
}
