#include <bits/stdc++.h>
using namespace std;
int64_t N, X;
int main() {
  cin >> N >> X;
  int64_t ret = N + X;
  int64_t current = N - X;
  while (X < current) {
    ret += 2 * X;
    current -= X;
  }
  ret += X - current;
  cout << ret << endl;
  return 0;
}
