#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long a, b, area;
  cin >> a >> b;
  area = a + b;
  vector<long long> v1, va, vb;
  for (long long i = 1; i * i <= area; i++) {
    if (area % i == 0) v1.push_back(i);
  }
  for (long long i = 1; i * i <= a; i++) {
    if (a % i == 0) va.push_back(i);
  }
  for (long long i = 1; i * i <= b; i++) {
    if (b % i == 0) vb.push_back(i);
  }
  long long x, y, peri = 0;
  vector<long long>::iterator itr;
  for (long long i = v1.size() - 1; i >= 0; i--) {
    x = v1[i];
    y = area / x;
    itr = lower_bound(va.begin(), va.end(), x);
    if (*itr == x) {
      long long w = *itr;
      long long z = a / w;
      if (z <= y)
        break;
      else
        continue;
    } else {
      itr--;
      long long w = *itr;
      long long z = a / w;
      if (z <= y)
        break;
      else
        continue;
    }
  }
  peri = 2 * (x + y);
  for (long long i = v1.size() - 1; i >= 0; i--) {
    x = v1[i];
    y = area / x;
    itr = lower_bound(vb.begin(), vb.end(), x);
    if (*itr == x) {
      long long w = *itr;
      long long z = b / w;
      if (z <= y)
        break;
      else
        continue;
    } else {
      itr--;
      long long w = *itr;
      long long z = b / w;
      if (z <= y)
        break;
      else
        continue;
    }
  }
  long long peri2 = 2 * (x + y);
  cout << min(peri, peri2) << "\n";
  return 0;
}
