#include <bits/stdc++.h>
using namespace std;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int main(void) {
  long long N, X;
  cin >> N >> X;
  long long ans = N;
  ans += ((N - X) / X) * X * 2;
  ans += 2 * X - N % X;
  cout << ans << endl;
}
