#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool uin(T& a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
inline bool uax(T& a, T b) {
  return a < b ? (a = b, true) : false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b, c;
  cin >> a >> b;
  c = (a + b);
  long long ans = 3e18, smol = 1e18;
  for (long long i = 1; i * i <= c; ++i) {
    if (a % i == 0) uin(smol, a / i);
    if (b % i == 0) uin(smol, b / i);
    if (c % i == 0) {
      if (smol <= c / i) uin(ans, 2LL * (i + (c / i)));
    }
  }
  cout << ans << '\n';
}
