#include <bits/stdc++.h>
using namespace std;
vector<long long> factor(long long n) {
  vector<long long> res;
  if (n % (long long)sqrt(n) == 0) res.push_back(sqrt(n));
  for (long long i = 1; i * i < n; i++) {
    if (n % i == 0) res.push_back(i);
  }
  return res;
}
signed main() {
  long long a, b;
  cin >> a >> b;
  vector<long long> da = factor(a), db = factor(b), dab = factor(a + b);
  long long minP = 1e18;
  for (auto f : dab) {
    for (auto x : da) {
      if (x <= f && a / x <= (a + b) / f) {
        minP = min(minP, 2 * (f + (a + b) / f));
        break;
      }
    }
    for (auto x : db) {
      if (x <= f && b / x <= (a + b) / f) {
        minP = min(minP, 2 * (f + (a + b) / f));
        break;
      }
    }
  }
  cout << minP;
}
