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