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