#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long a, b;
  cin >> a >> b;
  long long ar = a + b;
  long long ans = LLONG_MAX;
  vector<pair<long long int, long long int> > va, vb, vab;
  for (long long int i = 1; i < sqrt(ar) + 1; i++) {
    if (ar % i == 0) {
      vab.push_back({i, ar / i});
    }
  }
  for (long long int i = 1; i < sqrt(a) + 1; i++) {
    if (a % i == 0) {
      va.push_back({i, a / i});
    }
  }
  for (long long int i = 1; i < sqrt(b) + 1; i++) {
    if (b % i == 0) {
      vb.push_back({i, b / i});
    }
  }
  for (long long int i = 0; i < (long long int)va.size(); i++) {
    for (long long int j = 0; j < (long long int)vab.size(); j++) {
      if (va[i].first <= vab[j].first && va[i].second <= vab[j].second)
        ans = min(ans, 2 * (vab[j].first + vab[j].second));
    }
  }
  for (long long int i = 0; i < (long long int)vb.size(); i++) {
    for (long long int j = 0; j < (long long int)vab.size(); j++) {
      if (vb[i].first <= vab[j].first && vb[i].second <= vab[j].second)
        ans = min(ans, 2 * (vab[j].first + vab[j].second));
    }
  }
  cout << ans;
  return 0;
}
