input = gets.chomp.split(' ') l = input[0].to_i r = input[1].to_i c = input[2].to_i change_arr = [] for i in l..r do place = i*c num = 1 change = 0 while true change = num*1000-place if change >= 0 then break else num = num + 1 end end change_arr.push(change.to_i) end sorted_arr = change_arr.sort do |a, b| b <=> a end puts sorted_arr.last