#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
int main() {
  ull N, X;
  cin >> N >> X;
  ull ans = N;
  if (2 * X > N) {
    X = N - X;
  }
  if ((N - X) % X == 0) {
    ans += ((N - X) / X) * X * 2 - 1;
  } else {
    ans += ((N - X) / X) * X * 2;
    ans += X * 2 - 1;
  }
  cout << ans << endl;
  return 0;
}
