#include <bits/stdc++.h>
using namespace std;
int gcd(int m, int n) {
  if (m == 0 || n == 0) return 0;
  while (m != n) {
    if (m > n)
      m -= n;
    else
      n -= m;
  }
  return m;
}
int main() {
  long long int a, b;
  cin >> a >> b;
  cout << 3 * (a - gcd(a, b)) << endl;
}
