L, R, M = gets.split.map(&:to_i) l = L % M r = R % M limit = R - L + 1 sum = [M, [limit, (M - l + 1) + r].min].min puts sum