#include <bits/stdc++.h>
using namespace std;
inline long long gi() {
  long long f = 1, sum = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 3) + (sum << 1) + ch - '0';
    ch = getchar();
  }
  return f * sum;
}
long long n, x;
int main() {
  n = gi();
  x = gi();
  long long ans = 0, up = x, num = 0;
  ans += n;
  while (up < n - x) {
    ans += 2 * x;
    up += x;
    num++;
  }
  long long p = n - x - num * x;
  ans += x / p + p;
  printf("%lld\n", ans);
  return 0;
}
