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