#include <bits/stdc++.h>
using namespace std;
vector<int> veca, vecb;
int main() {
  long long a, b;
  scanf("%I64d %I64d", &a, &b);
  int sqa = sqrt(a);
  int sqb = sqrt(b);
  int i, j;
  for (i = 1; i <= sqa; i++) {
    if (a % i == 0) veca.push_back(i);
  }
  for (i = 1; i <= sqb; i++) {
    if (b % i == 0) vecb.push_back(i);
  }
  long long int sq = sqrt(a + b);
  long long int area = (a + b);
  for (i = sq; i >= 1; i--) {
    if (area % i == 0) {
      long long int val1 = i;
      long long int val2 = area / i;
      long long mx1 = max(val1, val2);
      long long mn1 = min(val1, val2);
      int l = 0, r = veca.size() - 1;
      long long value1 = -1;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (veca[mid] <= mn1) {
          l = mid + 1;
          value1 = veca[mid];
        } else
          r = mid - 1;
      }
      if (value1 != -1) {
        long long value2 = a / value1;
        long long int mx2 = max(value1, value2);
        long long int mn2 = min(value1, value2);
        if ((mx2 <= mx1) && (mn2 <= mn1)) {
          printf("%I64d\n", 2 * mn1 + 2 * mx1);
          return 0;
        }
      }
      l = 0, r = vecb.size() - 1;
      value1 = -1;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (vecb[mid] <= mn1) {
          l = mid + 1;
          value1 = vecb[mid];
        } else
          r = mid - 1;
      }
      if (value1 != -1) {
        long long value2 = b / value1;
        long long int mx2 = max(value1, value2);
        long long int mn2 = min(value1, value2);
        if (mx2 <= mx1 && mn2 <= mn1) {
          printf("%I64d\n", 2 * mn1 + 2 * mx1);
          return 0;
        }
      }
    }
  }
  printf("-1\n");
  return 0;
}
