#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, lim, p_min, min_v;
  cin >> a >> b;
  lim = a + b;
  vector<pair<long long, long long>> big_sides, a_sides, b_sides;
  for (long long w = 1LL; w * w <= lim; w++) {
    if (lim % w == 0) {
      big_sides.push_back(make_pair(w, lim / w));
    }
    if ((w * w <= a) && (a % w == 0)) {
      a_sides.push_back(make_pair(w, a / w));
    }
    if ((w * w <= b) && (b % w == 0)) {
      b_sides.push_back(make_pair(w, b / w));
    }
  }
  for (auto bit = big_sides.rbegin(); bit != big_sides.rend(); ++bit) {
    for (auto sit = a_sides.rbegin(); sit != a_sides.rend(); ++sit) {
      if ((bit->first >= sit->first) && (bit->second >= sit->second)) {
        cout << 2 * (bit->first + bit->second);
        return 0;
      }
    }
    for (auto sit = b_sides.rbegin(); sit != b_sides.rend(); ++sit) {
      if ((bit->first >= sit->first) && (bit->second >= sit->second)) {
        cout << 2 * (bit->first + bit->second);
        return 0;
      }
    }
  }
  return 0;
}
