#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (int i = 0; i < v.size(); i++) os << v[i] << " ";
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (typename set<T>::iterator it = v.begin(); it != v.end(); it++)
    os << *it << " ";
}
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int gi() {
  int w = 0;
  bool q = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') q = 0, c = getchar();
  while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar();
  return q ? w : -w;
}
int main() {
  long long a, b;
  cin >> a >> b;
  long long c = a + b;
  long long la = a, lb = b;
  long long ans = 1e18;
  for (long long p = 1; p * p <= c; p++) {
    if (a % p == 0) {
      la = a / p;
    }
    if (b % p == 0) {
      lb = b / p;
    }
    if (c % p == 0) {
      long long q = c / p;
      if (q >= la || q >= lb) ans = min(ans, 2 * (p + q));
    }
  }
  cout << ans;
  return 0;
}
