# frozen_string_literal: true L, R, M = gets.chomp.split.map(&:to_i) result = if R - L + 1 >= M M else range = L..R range.map { |i| i % M }.uniq.size end puts result