#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (auto& x : vec) is >> x;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (long long i = 0; i < (vec.size()); i++) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<vector<T> >& vec) {
  for (long long i = 0; i < (vec.size()); i++) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}
long long f(long long a, long long b) {
  if (a > b) return 2 * b + f(a - b, b);
  if (a < b) return a + b + f(b - a, a);
  if (a == b) return a + b;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  long long L, X;
  cin >> L >> X;
  long long ans = X + f(X, L - X);
  cout << ans << endl;
}
