#include <bits/stdc++.h>
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 0.00000000000000000000001;
using namespace std;
struct anush {
  long long divider1, divider2;
};
vector<anush> number[3];
void f(long long x, long long j) {
  for (long long i = 1; i * i <= x; i++)
    if (x % i == 0) {
      number[j].push_back({i, x / i});
    }
}
long long binarysearch(long long x, long long y) {
  long long l = 0, r = number[0].size() - 1;
  while (l + 1 < r) {
    long long d = (l + r) / 2;
    if (number[0][d].divider1 >= x)
      r = d;
    else if (number[0][l].divider2 < y)
      return -1;
    else
      l = d;
  }
  if (x > number[0][l].divider1) l = r;
  r = number[0].size() - 1;
  while (l + 1 < r) {
    long long d = (l + r) / 2;
    if (number[0][d].divider2 <= y)
      r = d;
    else
      l = d;
  }
  if (x <= number[0][r].divider1 && y <= number[0][r].divider2)
    return (number[0][r].divider1 + number[0][r].divider2) * 2;
  else if (x <= number[0][l].divider1 && y <= number[0][l].divider2)
    return (number[0][l].divider1 + number[0][l].divider2) * 2;
  else
    return -1;
}
long long ask(long long j) {
  long long mn = 1000000000000000000;
  for (long long i = 0; i < number[j].size(); i++) {
    long long x = binarysearch(number[j][i].divider1, number[j][i].divider2);
    if (x == -1) {
      continue;
    }
    mn = min(mn, x);
  }
  return mn;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a, b, c, mn = 1000000000000000000;
  cin >> a >> b;
  c = a + b;
  f(c, 0);
  f(a, 1);
  f(b, 2);
  for (long long i = 1; i <= 2; i++) {
    mn = min(mn, ask(i));
  }
  cout << mn;
  return 0;
}
