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