#include <bits/stdc++.h>
using namespace std;
long long a, b, c;
vector<long long> v1, v2, v3;
bool check(long long l, long long s) {
  long long r = s / l;
  for (auto width : v2) {
    long long len = c / width;
    if (width <= l && len <= r) return true;
  }
  return false;
}
int main() {
  cin >> a >> b;
  long long s = a + b;
  c = a;
  for (long long i = 1; i * i <= s; i++)
    if (s % i == 0) v1.push_back(i);
  for (long long i = 1; i * i <= c; i++)
    if (c % i == 0) v2.push_back(i);
  long long ans;
  for (int i = v1.size() - 1; i >= 0; i--) {
    long long l = v1[i], r = s / v1[i];
    if (check(l, s)) {
      ans = (v1[i] + s / v1[i]) * 2;
      break;
    }
  }
  c = b;
  v2.clear();
  for (long long i = 1; i * i <= c; i++)
    if (c % i == 0) v2.push_back(i);
  for (int i = v1.size() - 1; i >= 0; i--) {
    long long l = v1[i], r = s / v1[i];
    if (check(l, s)) {
      ans = min((v1[i] + s / v1[i]) * 2, ans);
      break;
    }
  }
  printf("%I64d", ans);
  return 0;
}
