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