#include <bits/stdc++.h>
int main() {
  long long N = 2, X = 1, sum = 0, y = 0;
  scanf("%lld %lld", &N, &X);
  sum = N;
  if (N / 2 >= X) {
    sum += X * 2;
    y += N - 2 * X;
    sum += (X / y + 1) * y;
  } else {
    y += X / (N - X);
    sum += (y + 1) * (N - X);
  }
  printf("%lld\n", sum);
  return 0;
}
