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