#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
const long long INF = 1e18 + 7;
long long a, b, ans = INF;
vector<long long> D(const long long &n) {
  vector<long long> V;
  V.clear();
  for (long long i = 1; i <= (long long)(sqrt(n)); i++)
    if (n % i == 0) V.push_back(i);
  return V;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> a >> b;
  long long c = a + b;
  vector<long long> A = D(a), B = D(b), C = D(c);
  for (auto cc : C)
    for (auto aa : A) {
      long long ccc = c / cc, aaa = a / aa;
      if (aa <= cc && aaa <= ccc) ans = min(ans, (cc + ccc) * 2);
    }
  for (auto cc : C)
    for (auto bb : B) {
      long long ccc = c / cc, bbb = b / bb;
      if (bb <= cc && bbb <= ccc) ans = min(ans, (cc + ccc) * 2);
    }
  cout << ans;
  return 0;
}
