#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
  Finish_read = 0;
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x *= f;
  Finish_read = 1;
}
template <class T>
inline void print(T x) {
  if (x / 10 != 0) print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void writeln(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
  putchar('\n');
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
}
long long x, y, ans = 1e18;
int mx[20000005], my[20000005];
int main() {
  cin >> x >> y;
  for (long long i = 1; i * i <= x; ++i)
    if (x % i == 0) mx[i] = i;
  for (long long i = 1; i * i <= y; ++i)
    if (y % i == 0) my[i] = i;
  for (int i = 1; i <= 2e7; ++i)
    if (!mx[i]) mx[i] = mx[i - 1];
  for (int i = 1; i <= 2e7; ++i)
    if (!my[i]) my[i] = my[i - 1];
  long long z = x + y;
  for (long long i = 1; i * i <= z; ++i)
    if (z % i == 0) {
      long long p = mx[i], a = my[i], tmp = z / i;
      if (p) {
        long long q = x / p;
        if (tmp >= q) ans = min(ans, 2 * (tmp + i));
      }
      if (a) {
        long long b = y / a;
        if (tmp >= b) ans = min(ans, 2 * (tmp + i));
      }
    }
  cout << ans << endl;
}
