#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const long long inf = 0x7fffffffffffffff;
const int MAXN = 200010;
int main() {
  long long n, m;
  cin >> n >> m;
  long long sum = n + m;
  long long k = sqrt(sum);
  vector<long long> a, b, c;
  for (int i = 1; i <= k; i++) {
    if (sum % i == 0) {
      a.push_back(i);
    }
  }
  k = sqrt(n);
  for (int i = 1; i <= k; i++) {
    if (n % i == 0) {
      b.push_back(i);
    }
  }
  k = sqrt(m);
  for (int i = 1; i <= k; i++) {
    if (m % i == 0) {
      c.push_back(i);
    }
  }
  long long ans = inf;
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < b.size(); j++) {
      if (b[j] > a[i]) break;
      if (sum / a[i] >= n / b[j]) ans = min(ans, (a[i] + sum / a[i]) * 2);
    }
    for (int j = 0; j < c.size(); j++) {
      if (c[j] > a[i]) break;
      if (sum / a[i] >= m / c[j]) ans = min(ans, (a[i] + sum / a[i]) * 2);
    }
  }
  cout << ans << endl;
}
