L,R,M =map(int,input().split()) N =R-L+1 N =N%M if N==0: N=M print(N)