#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
using namespace std;
using ll = long long;
inline ll nextLong() {
  ll n;
  scanf("%lld", &n);
  return n;
}
inline int nextInt() {
  int n;
  scanf("%d", &n);
  return n;
}
inline double nextDouble() {
  double n;
  scanf("%lf", &n);
  return n;
}
inline string nextLine() {
  static char ______________buffer[1000005];
  fgets(______________buffer, 1000000, stdin);
  string res = ______________buffer;
  if (*(res.end() - 1) == '\n') res.erase(res.end() - 1);
  return res;
}
inline char nextChar() {
  char n;
  scanf("%c", &n);
  return n;
}
inline string next() {
  static char ______________buffer[1000005];
  scanf("%s", ______________buffer);
  string res = ______________buffer;
  return res;
}
bool check(ll A, ll B, ll a, ll b) {
  for (ll i = 1; i <= A; i++) {
    if (a % i == 0) {
      ll m = i;
      ll n = a / m;
      if (n <= B) return true;
    }
    if (b % i == 0) {
      ll m = i;
      ll n = b / m;
      if (n <= B) return true;
    }
  }
  return false;
}
int main() {
  ll a, b;
  scanf("%lld %lld", &a, &b);
  ll mn = LLONG_MAX;
  ll mxA = 1;
  while (mxA * mxA <= a + b) mxA++;
  for (ll A = mxA - 1; A >= 1; A--) {
    if ((a + b) % A == 0) {
      ll B = (a + b) / A;
      if (check(A, B, a, b)) {
        mn = min(mn, 2 * (A + B));
        break;
      }
    }
  }
  printf("%lld", mn);
  return 0;
}
