#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
bool check(int u, long long v) {
  for (int i = 1; i <= u; i++) {
    if (a % i == 0) {
      long long rep = a / i;
      if (i <= u && rep <= v) return true;
    }
  }
  for (int i = 1; i <= u; i++) {
    if (b % i == 0) {
      long long rep = b / i;
      if (i <= u && rep <= v) return true;
    }
  }
  return false;
}
int main() {
  cin >> a >> b;
  c = a + b;
  for (int i = (int)sqrt(c); i; i--) {
    if (c % i == 0) {
      d = c / i;
      if (check(i, d)) {
        cout << (long long)(2 * (d + i)) << endl;
        return 0;
      }
    }
  }
}
