#include <bits/stdc++.h>
using namespace std;
const int N = 7e6;
long long a, b, ans, a1[N], a2[N], b1[N], b2[N];
int main() {
  scanf("%lld%lld", &a, &b);
  for (int i = 1; (long long)i * i <= a; ++i) {
    if (a % i != 0) continue;
    a1[++*a1] = i;
    a2[++*a2] = a / i;
  }
  a1[++*a1] = 1e17;
  a2[++*a2] = 1e17;
  for (int i = 1; (long long)i * i <= b; ++i) {
    if (b % i != 0) continue;
    b1[++*b1] = i;
    b2[++*b2] = b / i;
  }
  b1[++*b1] = 1e17;
  b2[++*b2] = 1e17;
  ans = 1e18;
  for (int i = 1; (long long)i * i <= a + b; ++i) {
    if ((a + b) % i != 0) continue;
    long long j = (a + b) / i;
    int pa = upper_bound(a1 + 1, a1 + 1 + *a1, i) - a1 - 1;
    if (pa >= 1 && a2[pa] <= j) {
      ans = min(ans, 2 * (i + j));
      continue;
    }
    int pb = upper_bound(b1 + 1, b1 + 1 + *b1, i) - b1 - 1;
    if (pb >= 1 && b2[pb] <= j) {
      ans = min(ans, 2 * (i + j));
    }
  }
  printf("%lld\n", ans);
  return 0;
}
