#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long a, b;
  cin >> a >> b;
  long long c = a + b;
  vector<long long> A, B, C;
  double kek = sqrt(a);
  for (int i = 1; i <= kek; i++)
    if (a % i == 0) A.push_back(i);
  kek = sqrt(b);
  for (int i = 1; i <= kek; i++)
    if (b % i == 0) B.push_back(i);
  kek = sqrt(c);
  for (int i = 1; i <= kek; i++)
    if (c % i == 0) C.push_back(i);
  long long x;
  for (int i = C.size() - 1; i >= 0; i--) {
    x = C[i];
    long long j = 0;
    while (j < A.size() && A[j] <= x) j++;
    if (j > 0) {
      long long y = A[j - 1];
      if (c / x >= a / y) break;
    }
    j = 0;
    while (j < B.size() && B[j] <= x) j++;
    if (j > 0) {
      long long y = B[j - 1];
      if (c / x >= b / y) break;
    }
  }
  cout << (x + c / x) * 2;
}
