l,r,m=map(int,input().split()) 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(m-(l%m)+(r%m)+1) else: print(m)