def main(): l, r, n = map(int, input().split()) l_rest = l % n if l_rest == 0: l_rest = n r_rest = r % n l_set_start = l + (n - l_rest) r_set_end = r - r_rest if l_set_start < r_set_end: print(n) return if l_set_start > r_set_end: print(r-l+1) return print(min(n-l_rest+r_rest+1, n)) if __name__ == "__main__": main()