#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, gcd;
  cin >> a >> b;
  for (int i = 1; i < 2 / a; ++i) {
    if (a % i == 0 && b % i == 0) {
      gcd = i;
    }
  }
  cout << 3 * (a - gcd) << endl;
}
