#include <bits/stdc++.h>
long long dividors[20000000];
long long solve(long long sum, long long a) {
  int t = 0;
  for (long long i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      dividors[t++] = i;
    }
  }
  long long c = -1;
  for (long long i = 1; i * i <= sum; i++) {
    if (sum % i == 0) {
      int low = 0;
      int high = t - 1;
      int found = -1;
      while (low <= high) {
        int mid = (low + high) >> 1;
        if (dividors[mid] <= i) {
          found = mid;
          low = mid + 1;
        } else {
          high = mid - 1;
        }
      }
      if (found >= 0 && dividors[found] <= i &&
          a / dividors[found] <= sum / i) {
        c = i;
      }
    }
  }
  if (c < 0) {
    return -1;
  }
  return (c + (sum / c)) << 1;
}
int main() {
  long long a, b;
  scanf("%lld%lld", &a, &b);
  long long t1 = solve(a + b, a);
  long long t2 = solve(a + b, b);
  if (t1 > 0 && t2 > 0) {
    printf("%lld\n", t1 < t2 ? t1 : t2);
  } else if (t1 > 0) {
    printf("%lld\n", t1);
  } else {
    printf("%lld\n", t2);
  }
  return 0;
}
