#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
vector<long long> getdiv(long long x) {
  vector<long long> div;
  for (long long i = 1; i * i <= x; i++)
    if (x % i == 0) div.push_back(i);
  return div;
}
long long solve(long long a, long long b) {
  vector<long long> diva = getdiv(a);
  for (auto &x : diva) x = a / x;
  reverse(diva.begin(), diva.end());
  vector<long long> divab = getdiv(a + b);
  long long ans = inf;
  for (long long x : divab) {
    long long y = (a + b) / x;
    auto it = upper_bound(diva.begin(), diva.end(), y);
    if (it == diva.begin()) continue;
    it--;
    long long na = *it;
    if (a / na <= x) ans = min(ans, 2 * (x + y));
  }
  return ans;
}
int main() {
  long long a, b;
  cin >> a >> b;
  cout << min(solve(a, b), solve(b, a));
  return 0;
}
