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