#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                           'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;
ll GCD(ll a, ll b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
  ll gcd = GCD(a, b);
  return a / gcd * b;
}
ll A[100010];
;
int main() {
  int N, X;
  cin >> N;
  cin >> X;
  cout << (X + N - X) + (N / X - 1) * 2 * X + 2 * X - 1 << endl;
  return 0;
}
