#include <bits/stdc++.h>
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f;
unsigned long long int a, b, tot, head = 0;
unsigned long long int ans = inf, an[maxn];
unsigned long long int solve(unsigned long long int a,
                             unsigned long long int b) {
  ans = 2 * (a + b) + 2;
  tot = a + b;
  head = 0;
  for (register unsigned long long int i = 1; i * i <= a; ++i) {
    if (a % i == 0) {
      an[++head] = i;
    }
  }
  int l = 1;
  for (unsigned long long int i = 1; i * i <= tot; ++i) {
    if (tot % i == 0) {
      while (l + 1 <= head && an[l + 1] <= i) ++l;
      if (tot / i >= a / an[l]) {
        ans = std::min(ans, 2 * (tot / i + i));
      }
    }
  }
  return ans;
}
int main() {
  std::cin >> a >> b;
  std::cout << std::min(solve(a, b), solve(b, a));
  return 0;
}
