#include <bits/stdc++.h>
using namespace std;
const int MM = 2e5 + 5, MOD = 1e9 + 7;
long long A, B, AB, ans;
vector<int> d[3];
void factor(long long nm, int tp) {
  for (long long i = 1; i * i <= nm; i++) {
    if (nm % i == 0) d[tp].push_back(i);
  }
}
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cin >> A >> B;
  AB = A + B;
  ans = 1e18;
  factor(AB, 0);
  factor(A, 1);
  factor(B, 2);
  for (int i = 0, aix = 0, bix = 0; i < d[0].size(); i++) {
    while (aix < d[1].size() - 1 && d[1][aix + 1] <= d[0][i]) aix++;
    while (bix < d[2].size() - 1 && d[2][bix + 1] <= d[0][i]) bix++;
    if (AB / d[0][i] >= A / d[1][aix])
      ans = min(ans, 2 * (d[0][i]) + 2 * (AB / d[0][i]));
    if (AB / d[0][i] >= B / d[2][bix])
      ans = min(ans, 2 * (d[0][i]) + 2 * (AB / d[0][i]));
  }
  cout << ans << "\n";
}
