#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MXD = 2e7 + 7;
int cnta[MXD], cntb[MXD];
ll a, b, S, res;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b;
  S = a + b;
  for (ll i = 1; i * i <= S; ++i) {
    if (a % i == 0) cnta[i] = 1;
    cnta[i] += cnta[i - 1];
  }
  for (ll i = 1; i * i <= S; ++i) {
    if (b % i == 0) cntb[i] = 1;
    cntb[i] += cntb[i - 1];
  }
  for (ll i = 1; i * i <= S; ++i) {
    if (S % i) continue;
    int ia = (int)ceil(1.0 * a * i / S) - 1;
    int ib = (int)ceil(1.0 * b * i / S) - 1;
    if ((cnta[i] - cnta[ia]) || (cntb[i] - cntb[ib])) res = 2 * (i + S / i);
  }
  cout << res;
  return 0;
}
