#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, ans = 1000000000000000;
  cin >> a >> b;
  long long v = (a + b);
  vector<pair<long long, long long>> vals, vals2, vals3;
  for (long long i = 1; i <= sqrt(v); i += 1) {
    if (v % i == 0) {
      vals.push_back({i, v / i});
    }
  }
  for (long long i = 1; i <= sqrt(a); i += 1) {
    if (a % i == 0) {
      vals2.push_back({i, a / i});
    }
  }
  for (long long i = 1; i <= sqrt(b); i += 1) {
    if (b % i == 0) {
      vals3.push_back({i, b / i});
    }
  }
  for (pair<long long, long long> i : vals2) {
    for (pair<long long, long long> j : vals) {
      if (i.first <= j.first && i.second <= j.second) {
        ans = min(ans, 2 * j.first + 2 * j.second);
      }
    }
  }
  for (pair<long long, long long> i : vals3) {
    for (pair<long long, long long> j : vals) {
      if (i.first <= j.first && i.second <= j.second) {
        ans = min(ans, 2 * j.first + 2 * j.second);
      }
    }
  }
  cout << ans;
}
