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