#include <bits/stdc++.h>
using namespace std;
long long a, b, ans1 = (int)1e14, ans2 = (int)1e14;
long long A[(int)1e7 + 1], B[(int)1e7 + 1], ta, tb;
int main() {
  scanf("%lld%lld", &a, &b);
  int c = sqrt((double)a), d = sqrt((double)b), e = sqrt((double)(a + b));
  for (int i = 1; i <= c; ++i)
    if (!(a % i)) A[++ta] = i;
  for (int i = 1; i <= d; ++i)
    if (!(b % i)) B[++tb] = i;
  for (int i = e; i >= 1; --i) {
    if ((a + b) % i) continue;
    while (A[ta] > i && ta) --ta;
    if (a / A[ta] <= (a + b) / i) {
      ans1 = 2ll * (1ll * i + (a + b) / i);
      break;
    }
  }
  for (int i = e; i >= 1; --i) {
    if ((a + b) % i) continue;
    while (B[tb] > i && tb) --tb;
    if (b / B[tb] <= (a + b) / i) {
      ans2 = 2ll * (1ll * i + (a + b) / i);
      break;
    }
  }
  printf("%lld", min(ans1, ans2));
  return 0;
}
