#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long a, b;
  cin >> a >> b;
  long long s = a + b;
  vector<long long> v, v1, v2;
  for (long long i = 1; i * i <= s; i++) {
    if (s % i == 0) {
      v.push_back(i);
    }
  }
  for (long long i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      v1.push_back(i);
    }
  }
  for (long long i = 1; i * i <= b; i++) {
    if (b % i == 0) {
      v2.push_back(i);
    }
  }
  long long len = v.size();
  bool flag = false;
  for (long long i = len - 1; i >= 0; i--) {
    long long l = lower_bound(v1.begin(), v1.end(), v[i]) - v1.begin();
    if (l != v1.size() && v1[l] == v[i]) {
      cout << 2 * ((s / v[i]) + v[i]);
      flag = true;
      break;
    } else {
      if (l != 0) {
        l--;
        if (a / v1[l] <= s / v[i]) {
          cout << 2 * ((s / v[i]) + v[i]);
          flag = true;
          break;
        }
      }
    }
    l = lower_bound(v2.begin(), v2.end(), v[i]) - v2.begin();
    if (l != v2.size() && v2[l] == v[i]) {
      cout << 2 * ((s / v[i]) + v[i]);
      flag = true;
      break;
    } else {
      if (l != 0) {
        l--;
        if (b / v2[l] <= s / v[i]) {
          cout << 2 * ((s / v[i]) + v[i]);
          flag = true;
          break;
        }
      }
    }
  }
  if (flag == false) {
    cout << 2 * (s + 1);
  }
  return 0;
}
