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