#include <bits/stdc++.h>
using namespace std;
long long solve(long long a, long long b) {
  long long ans = 2 * (a + b) + 2;
  vector<long long> v;
  for (long long i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      v.push_back(i);
    }
  }
  long long x = a + b;
  for (long long i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      auto it = upper_bound(v.begin(), v.end(), i);
      if (it != v.begin()) {
        it--;
        if (a / (*it) <= x / i) {
          ans = min(ans, (i + x / i) * 2);
        }
      }
    }
  }
  return ans;
}
void nikal_pehli_fursat_mai() {
  long long a, b;
  cin >> a >> b;
  cout << min(solve(a, b), solve(b, a)) << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tc = 1;
  while (tc--) {
    nikal_pehli_fursat_mai();
  }
}
