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