#include <bits/stdc++.h>
using namespace std;
long long int const MOD = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int N, X;
  cin >> N >> X;
  if (N % 2 == 0 && N / 2 == X) {
    cout << 3 * N / 2 << endl;
  } else if (N % 2 != 0 && N / 2 >= X) {
    long long int ans = 0;
    ans += N;
    long long int turn1 = (N - X) / X;
    ans += (turn1)*X * 2;
    long long int turn2 = (N - X) - (turn1)*X;
    ans += X * 2 - turn2;
    cout << ans << endl;
  } else {
    long long int ans = 0;
    ans += X;
    ans += X * 2;
    cout << ans << endl;
  }
  return 0;
}
