#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N, X;
  cin >> N >> X;
  int64_t d = N - (X << 1), ans = N + X;
  while (d > 0) {
    ans += (X << 1) + (X - 1) / d * d;
    d -= X - (X - 1) / d * d;
  }
  cout << ans;
  return 0;
}
