L, R, M = map(int, input().strip().split()) if L//M + R//M <= 1: print(min(R-L+1, M)) else: print(M)