#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int oo = 1e9 + 5;
const long long mod = 1e9 + 7;
long long sqr(long long x) { return x * x; }
deque<pair<long long, long long> > q1, q2, q3;
int main() {
  long long a, b;
  cin >> a >> b;
  long long t = (a + b);
  for (long long i = 1; i * i <= t; i++)
    if (t % i == 0) q1.push_front(pair<long long, long long>(i, t / i));
  for (long long i = 1; i * i <= a; i++)
    if (a % i == 0) q2.push_front(pair<long long, long long>(i, a / i));
  for (long long i = 1; i * i <= b; i++)
    if (b % i == 0) q3.push_front(pair<long long, long long>(i, b / i));
  int l = 0, r = 0;
  for (int i = 0; i < q1.size(); i++) {
    while (l < q2.size() && q2[l].second <= q1[i].second) l++;
    while (r < q3.size() && q3[r].second <= q1[i].second) r++;
    l--;
    r--;
    if (l >= 0 && q2[l].first <= q1[i].first) {
      cout << (q1[i].first + q1[i].second) * 2 << endl;
      return 0;
    }
    if (r >= 0 && q3[r].first <= q1[i].first) {
      cout << (q1[i].first + q1[i].second) * 2 << endl;
      return 0;
    }
    l++;
    r++;
  }
  return 0;
}
