#include <bits/stdc++.h>
using namespace std;
long v[1000000];
long long int smallest_enclosure(long long int a, long long int b) {
  int n = 0;
  for (long long int i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      v[n] = i;
      n++;
    }
  }
  long long int ans = 2 * (a + b) + 2;
  long long int x = a + b;
  int l = 0;
  for (long long int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      while (l + 1 < n && v[l + 1] <= i) l++;
      if (a / v[l] <= x / i) ans = min(ans, (i + x / i) * 2);
    }
  }
  return ans;
}
int main() {
  long long int a, b;
  scanf("%lld%lld", &a, &b);
  printf("%lld", min(smallest_enclosure(a, b), smallest_enclosure(b, a)));
  return 0;
}
