def getlist(): return list(map(int, input().split())) L, R, M = getlist() l = L % M r = R % M if R - L >= M: print(M) else: if r >= l: print(r - l + 1) else: print(M + r - l)