l, = gets.split(' ').map(&:to_i)

minimum = 2018

(l...(l + 2019)).each do |i|
  ((i + 1)...(i + 2020)).each do |j|
    rem = (i % 2019) * (j % 2019) % 2019
    minimum = rem if rem < minimum
  end
end

print minimum
