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