L,R,M=map(int,input().split()) left=L%M right=R%M if R-L<=M-1: print(R-L+1) else: print(right-left+1 if right>left else right+M-left+1)