l,r,m = map(int,input().split()) if m-1 < r-l: print(m) elif l//m == r//m: print(r-l+1) else: s = {i%m for i in range(l,r+1)} print(len(s))