#include <bits/stdc++.h>
using namespace std;
unsigned long long ans;
void solve(unsigned long long a, unsigned long long b) {
  unsigned long long sum = a + b;
  unsigned long long edg[1000005];
  int k = 1, l = 0, r = 0;
  for (unsigned long long i = 1; i * i <= a; ++i) {
    if (a % i == 0) {
      edg[k] = i;
      ;
      k++;
    }
  }
  r = k;
  for (unsigned long long i = 1; i * i <= sum; ++i) {
    if (sum % i == 0) {
      unsigned long long x = sum / i;
      while (l + 1 < k && edg[l + 1] <= i) l++;
      ;
      if (x >= a / edg[l]) {
        ans = min(ans, (i + x) * 2);
        ;
      }
    }
  };
}
int main() {
  unsigned long long a, b;
  cin >> a >> b;
  ans = (a + b) * 2 + 2;
  solve(a, b);
  solve(b, a);
  printf("%lld\n", ans);
  return 0;
}
