l,r,m = map(int,input().split()) if r - l >= m: print(m) else: if l%m > r%m: print((m-(l%m)+1)+r%m) else: print(r%m-l%m+1)