#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int llINF = 0x3f3f3f3f3f3f3f;
vector<int> div1;
long long int a, b;
long long int solve(long long int x) {
  vector<int> div2;
  for (long long int i = 1; i * i <= x; i++)
    if (x % i == 0) div2.push_back(i);
  long long int ans = llINF;
  for (auto c : div1) {
    long long int d = (a + b) / c;
    auto it = upper_bound(div2.begin(), div2.end(), c);
    it--;
    long long int e = *it;
    long long int f = x / e;
    if (d >= f) ans = min(ans, 2 * (c + d));
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> a >> b;
  for (long long int i = 1; i * i <= a + b; i++) {
    if ((a + b) % i == 0) div1.push_back(i);
  }
  long long int ans = solve(a);
  ans = min(solve(b), ans);
  cout << ans << endl;
}
