#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int iinf = INT_MAX;
const long long linf = 2e18;
const double dinf = 1e30;
const int MOD = 1000000007;
inline int read() {
  int X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
void print(int x) {
  cout << x << '\n';
  exit(0);
}
void PRINT(string x) {
  cout << x << '\n';
  exit(0);
}
void douout(double x) { printf("%lf\n", x + 0.0000000001); }
long long ans = 1e18, a, b, mx = 1e18;
int main() {
  cin >> a >> b;
  for (long long i = 1; i * i <= (a + b); i++) {
    if (a % i == 0) mx = min(mx, a / i);
    if (b % i == 0) mx = min(mx, b / i);
    if ((a + b) % i == 0 && (a + b) / i >= mx)
      ans = min(ans, 2 * i + 2 * ((a + b) / i));
  }
  cout << ans;
}
