L,R,M=[int(i) for i in input().split()] L%=M R%=M if abs(R-L)>=M: print(M) elif L