L, K = map(int, input().split()) i = L / (2 * K) if L % (2 * K) ==0: print(int(L / 2 - K)) elif 2 > i > 1: print(K) else: print(int(i) * K)