#include <bits/stdc++.h>
using namespace std;
int f(pair<long long, long long> &a, pair<long long, long long> &b) {
  return a.first + a.second <= b.first + b.second;
}
int main() {
  long long a, b, i;
  int test = 0;
  vector<pair<long long, long long> > v, va, vb;
  vector<pair<long long, long long> >::iterator it, ita, itb;
  pair<long long, long long> x;
  cin >> a >> b;
  for (i = 1; i <= sqrt(a + b); i++) {
    if ((a + b) % i == 0) v.push_back(make_pair(i, (a + b) / i));
  }
  sort(v.begin(), v.end(), f);
  for (i = 1; i <= sqrt(a); i++)
    if (a % i == 0) va.push_back(make_pair(i, (a / i)));
  for (i = 1; i <= sqrt(b); i++)
    if (b % i == 0) vb.push_back(make_pair(i, (b / i)));
  sort(va.begin(), va.end(), f);
  sort(vb.begin(), vb.end(), f);
  it = v.begin();
  while (it != v.end()) {
    for (ita = va.begin(); ita != va.end(); ita++)
      if (ita->first <= it->first && ita->second <= it->second) {
        test = 1;
        break;
      }
    if (test == 1) break;
    for (itb = vb.begin(); itb != vb.end(); itb++)
      if (itb->first <= it->first && itb->second <= it->second) {
        test = 1;
        break;
      }
    if (test == 1) break;
    it++;
  }
  cout << 2 * (it->first + it->second);
  return 0;
}
