#include <bits/stdc++.h>
using namespace std;
long long a, b, ab, ans = 10000000000000000LL;
vector<long long> da, db, dab;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> a >> b;
  ab = a + b;
  for (int i = 1; i <= sqrt(a); i++) {
    if (a % i == 0) da.push_back(i);
  }
  for (int i = 1; i <= sqrt(b); i++) {
    if (b % i == 0) db.push_back(i);
  }
  for (int i = 1; i <= sqrt(ab); i++) {
    if (ab % i == 0) dab.push_back(i);
  }
  for (auto i : dab) {
    bool works = false;
    for (auto j : da) {
      if (j <= i && a / j <= ab / i) {
        works = true;
        break;
      }
    }
    for (auto j : db) {
      if (j <= i && b / j <= ab / i) {
        works = true;
        break;
      }
    }
    if (works) ans = min(ans, i + ab / i);
  }
  cout << ans * 2;
}
