#include <bits/stdc++.h>
using namespace std;
long long a, b;
vector<long long> A, B, C;
int main() {
  scanf("%lld %lld", &a, &b);
  for (long long i = 1; i <= sqrt(a); i++)
    if (a % i == 0) A.push_back(i);
  for (long long i = 1; i <= sqrt(b); i++)
    if (b % i == 0) B.push_back(i);
  for (long long i = 1; i <= sqrt(a + b); i++)
    if ((a + b) % i == 0) C.push_back(i);
  long long ans;
  for (long long i : C) {
    for (long long j : A) {
      if (j <= i && a / j <= (a + b) / i) ans = 2 * i + (2 * (a + b) / i);
    }
    for (long long j : B) {
      if (j <= i && b / j <= (a + b) / i) ans = 2 * i + (2 * (a + b) / i);
    }
  }
  printf("%lld\n", ans);
}
