L, K = map(int, input().split()) l = 0 for i in range(L): if L > K: L = L - 2 * K l = l + K print(l)