#include <bits/stdc++.h>
using namespace std;
void findDivisors(long long input, vector<long long> &divs) {
  long long g = 1;
  while (g * g <= input) {
    if (input % g == 0) divs.push_back(g);
    g++;
  }
}
int main() {
  long long a, b;
  scanf("%lld %lld", &a, &b);
  long long totalBlocks = a + b;
  vector<long long> divisorsOfBlock;
  findDivisors(totalBlocks, divisorsOfBlock);
  vector<long long> aDivisors;
  findDivisors(a, aDivisors);
  vector<long long> bDivisors;
  findDivisors(b, bDivisors);
  long long minPed = LONG_LONG_MAX, height, width, currentPedimeter,
            currentWidth;
  bool flag;
  for (auto i : divisorsOfBlock) {
    height = i, width = (totalBlocks / height);
    currentPedimeter = 2 * (height + width);
    flag = true;
    for (auto g : aDivisors) {
      if (g <= height) {
        currentWidth = a / g;
        if (currentWidth <= width) {
          minPed = min(currentPedimeter, minPed);
          flag = false;
          break;
        }
      }
    }
    if (flag) {
      for (auto g : bDivisors) {
        if (g <= height) {
          currentWidth = b / g;
          if (currentWidth <= width) {
            minPed = min(currentPedimeter, minPed);
            break;
          }
        }
      }
    }
  }
  printf("%lld\n", minPed);
  return 0;
}
