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