#include <bits/stdc++.h>
using namespace std;
long long a, b;
set<pair<long long, long long> > as, bs;
void get_fact() {
  for (long long i = 1; i * i <= a; ++i)
    if (a % i == 0) as.insert(make_pair(i, a / i));
  for (long long i = 1; i * i <= b; ++i)
    if (b % i == 0) bs.insert(make_pair(i, b / i));
}
bool check(long long x, long long y) {
  for (auto const &e : as) {
    if (e.first <= x && e.second <= y) {
      return true;
    }
  }
  for (auto const &e : bs) {
    if (e.first <= x && e.second <= y) {
      return true;
    }
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> a >> b;
  get_fact();
  long long tot = a + b;
  long long beg = 1, last;
  for (; beg * beg <= tot; ++beg) last = beg;
  beg = last;
  for (long long i = beg; i >= 1; --i) {
    if (tot % i == 0 && check(i, tot / i)) {
      cout << (tot / i + i) * 2 << endl;
      break;
    }
  }
  return 0;
}
