#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const long long MAXN = (long long)200010;
uint64_t n, k;
vector<int> a[MAXN];
long long d[MAXN] = {};
long long s(long long a, long long b) {
  long long k = 0;
  for (long long i = 1; i * i <= b; ++i) {
    if (b % i == 0) {
      d[k++] = i;
    }
  }
  long long ans = 2 * (a + b) + 2;
  long long x = a + b;
  long long l = 0;
  for (long long i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      while (l + 1 < k && d[l + 1] <= i) ++l;
      if (b / d[l] <= x / i) ans = min(ans, (i + x / i) * 2);
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a, b;
  cin >> a >> b;
  cout << min(s(a, b), s(b, a));
  return 0;
}
