#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
void fast() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
vector<pair<long long, long long>> sa, sb;
long long a, b;
bool valid(long long i, long long j) {
  for (auto x : sa) {
    if (x.first <= i && x.second <= j || x.first <= j && x.second <= i)
      return true;
  }
  for (auto x : sb) {
    if (x.first <= i && x.second <= j || x.first <= j && x.second <= i)
      return true;
  }
  return false;
}
int main() {
  fast();
  ;
  cin >> a >> b;
  for (long long i = 1; i <= sqrt(a); i++) {
    if (a % i == 0) sa.push_back({i, a / i});
  }
  for (long long i = 1; i <= sqrt(b); i++) {
    if (b % i == 0) sa.push_back({i, b / i});
  }
  long long z = a + b;
  long long mn = LLONG_MAX;
  for (long long i = 1; i <= sqrt(z); i++) {
    if (z % i == 0) {
      if (valid(i, z / i)) {
        mn = min(mn, (i + z / i) * 2);
      }
    }
  }
  cout << mn << "\n";
}
