#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  cin >> a >> b;
  long long s = a + b;
  long long d_a = sqrt(a), d_b = sqrt(b);
  for (long long i = sqrt(s); i >= 1; --i) {
    if (s % i == 0) {
      long long d1 = s / i;
      long long perim = 2 * (d1 + i);
      bool b_a = false;
      bool b_b = false;
      while (a % d_a != 0 || d_a > i) {
        d_a--;
      }
      if (a / d_a <= d1) {
        b_a = true;
      }
      while (b % d_b != 0 || d_b > i) {
        d_b--;
      }
      if (b / d_b <= d1) {
        b_b = true;
      }
      if (b_a || b_b) {
        cout << perim << endl;
        break;
      }
    }
  }
  return 0;
}
