#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const double eps = 1e-9;
const int MAX_N = 1e6 + 5;
const int inf = 2e9;
const long long Inf = (long long)1e18;
const long long M = (long long)1e9 + 7;
int Int() {
  int x;
  scanf("%d", &x);
  return x;
}
long long Long() {
  long long x;
  scanf("%lld", &x);
  return x;
}
void Char(char* ch) { scanf("%s", ch); }
template <typename t>
inline t abs(t a) {
  if (a >= 0) return a;
  return -a;
}
template <typename t>
inline t gcd(t a, t b) {
  return !b ? a : gcd(b, a % b);
}
template <typename t>
inline t lcm(t a, t b) {
  return a * (b / gcd(a, b));
}
template <typename T>
inline T modpow(T b, T p, T Mod) {
  T res = 1;
  while (p) {
    if (p & 1) {
      res *= b;
      res %= Mod;
    }
    b *= b;
    b %= Mod;
    p >>= 1;
  }
  return res;
}
template <typename T>
inline T ModInv(T b, T Mod) {
  return modpow(b, Mod - 2, Mod);
}
template <typename T>
inline T pwr(T b, T p) {
  T res = 1;
  while (p) {
    if (p & 1) {
      res *= b;
    }
    b *= b;
    p >>= 1;
  }
  return res;
}
int e1, e2, d1;
template <typename T>
inline void extgcd(T a, T b) {
  if (!b) {
    e1 = 1, e2 = 0, d1 = a;
    return;
  }
  extgcd(b, a % b);
  T x1 = e2;
  T y1 = e1 - (a / b) * e2;
  e1 = x1;
  e2 = y1;
}
template <typename T>
inline vector<T> Unique(vector<T> v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  return v;
}
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " ";
  err(++it, args...);
}
std::vector<long long> run(long long n) {
  std::vector<long long> L, R;
  for (long long i = 1LL; i * i <= n; i++) {
    long long x, y;
    if (n % i == 0) {
      L.push_back(i);
      R.push_back(n / i);
    }
  }
  reverse(R.begin(), R.end());
  L.insert(L.end(), R.begin(), R.end());
  return L;
}
int main() {
  int t = 1, tc = 0;
  while (t--) {
    long long a = Long(), b = Long();
    long long sum = a + b;
    std::vector<long long> A, B, S;
    A = run(a), B = run(b), S = run(sum);
    long long res = Inf;
    for (int i = 0, j = (int)S.size() - 1; i < j; i++, j--) {
      int u = lower_bound(A.begin(), A.end(), S[i]) - A.begin();
      if (A[u] > S[i]) {
        if (u != 0)
          u--;
        else
          continue;
      }
      long long k = A[u];
      long long p = a / k;
      if (k <= S[i] and p <= S[j]) {
        res = min(res, 2LL * (S[i] + S[j]));
        continue;
      }
      u = lower_bound(B.begin(), B.end(), S[i]) - B.begin();
      if (B[u] > S[i]) {
        if (u != 0)
          u--;
        else
          continue;
      }
      k = B[u];
      p = b / k;
      if (k <= S[i] and p <= S[j]) {
        res = min(res, 2LL * (S[i] + S[j]));
      }
    }
    cout << res << '\n';
  }
  return 0;
}
