#include <bits/stdc++.h>
using namespace std;
using ulli = unsigned long long int;
int main(void) {
  ulli L;
  ulli X;
  ulli N;
  cin >> N >> X;
  ulli DIS = N - X;
  ulli SRP = DIS % X;
  ulli DIV = DIS / X;
  ulli STR = (2 * (DIV - 1) + 1) * X;
  L = X + DIS + STR + X * 2 - SRP;
  if (SRP != 0) {
    L += X;
  }
  cout << L << endl;
}
