L, K= map(int, input().split()) count= L / (K*2) T_count= int(count) term= L % (K*2) if term != 0: if count <= 1: U_length= 0 else: U_length= K * T_count else: U_length= K * T_count - K print(U_length)