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