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