#include <bits/stdc++.h>
using namespace std;
long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long mod = 1e9 + 7;
const long long N = 300050;
long long valid(long long x, long long y, long long X, long long Y) {
  return ((x <= X && y <= Y) || (x <= Y && y <= X));
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long test = 1;
  while (test--) {
    long long a, b;
    cin >> a >> b;
    vector<long long> bade, chote1, chote2;
    for (long long i = 1; i * i <= a + b; i++) {
      if ((a + b) % i == 0) {
        bade.push_back(i);
      }
    }
    for (long long i = 1; i * i <= a; i++) {
      if (a % i == 0) {
        chote1.push_back(i);
      }
    }
    for (long long i = 1; i * i <= b; i++) {
      if (b % i == 0) {
        chote2.push_back(i);
      }
    }
    long long ans = LLONG_MAX;
    for (long long x : bade) {
      long long y = (a + b) / x, ok = 0;
      for (long long _x : chote1) {
        long long _y = a / _x;
        ok |= valid(_x, _y, x, y);
      }
      if (ok) ans = min(ans, 2 * (x + y));
    }
    for (long long x : bade) {
      long long y = (a + b) / x, ok = 0;
      for (long long _x : chote2) {
        long long _y = b / _x;
        ok |= valid(_x, _y, x, y);
      }
      if (ok) ans = min(ans, 2 * (x + y));
    }
    cout << ans << '\n';
  }
  return 0;
}
