#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long a, b;
  cin >> a >> b;
  long long n = a + b;
  vector<pair<long long, long long>> div_a, div_b;
  for (long long d = 1; d * d <= a; ++d) {
    if (a % d == 0) div_a.push_back({d, a / d});
  }
  for (long long d = 1; d * d <= b; ++d) {
    if (b % d == 0) div_b.push_back({d, b / d});
  }
  for (long long d = sqrt(n); d >= 1; --d) {
    if (n % d == 0) {
      long long c = n / d;
      for (auto elem : div_a) {
        if (elem.first <= d && elem.second <= c) {
          cout << (c + d) * 2 << endl;
          return 0;
        }
      }
      for (auto elem : div_b) {
        if (elem.first <= d && elem.second <= c) {
          cout << (c + d) * 2 << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}
