#include <bits/stdc++.h>
using namespace std;
void testCase() {}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long a, b;
  cin >> a >> b;
  vector<long long> pun;
  vector<long long> sin;
  for (long long i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      pun.push_back(i);
      if (a / i != i) pun.push_back(a / i);
    }
  }
  for (long long i = 1; i * i <= b; i++) {
    if (b % i == 0) {
      sin.push_back(i);
      if (b / i != i) sin.push_back(b / i);
    }
  }
  sort(pun.begin(), pun.end());
  sort(sin.begin(), sin.end());
  long long best = 2e18;
  long long sum = a + b;
  for (long long i = 1; i * i <= sum; i++) {
    if (sum % i == 0) {
      long long eka = i;
      long long toka = sum / i;
      auto it = upper_bound(pun.begin(), pun.end(), eka);
      it--;
      long long x = a / (*it);
      if (x <= toka) {
        best = min(best, 2 * (eka + toka));
      }
      it = upper_bound(sin.begin(), sin.end(), eka);
      it--;
      x = b / (*it);
      if (x <= toka) {
        best = min(best, 2 * (eka + toka));
      }
    }
  }
  cout << best << "\n";
}
