#include <bits/stdc++.h>
using namespace std;
const long long N = 2e3 + 100, MOD = 1e9 + 7, INF = 1e15, SQ = 350, LOG = 20;
int x1, x2, z, t, y2, maxi, maxi2, mini, ptr, a[N], b[N], p, q, k, sum1, sum2,
    dp[N];
long long ans, x, y, n, m;
vector<long long> v, v2;
int main() {
  cin >> n >> m;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
      v.push_back(n / i);
    }
  }
  for (long long i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      v2.push_back(i);
      v2.push_back(m / i);
    }
  }
  sort(v.begin(), v.end());
  sort(v2.begin(), v2.end());
  x = n + m;
  ans = INF;
  for (long long i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      y = x / i;
      int b = 0, e = v.size(), mid = 0;
      while (e - b > 1) {
        mid = e + b >> 1;
        if (v[mid] > i) {
          e = mid;
        } else {
          b = mid;
        }
      }
      if (v[b] <= i && (n / v[b]) <= y) {
        ans = min(ans, (i + i + y + y));
      }
      b = 0, e = v2.size(), mid = 0;
      while (e - b > 1) {
        mid = e + b >> 1;
        if (v2[mid] > i) {
          e = mid;
        } else {
          b = mid;
        }
      }
      if (v2[b] <= i && (m / v2[b]) <= y) {
        ans = min(ans, (i + i + y + y));
      }
    }
  }
  cout << ans;
}
