require "prime"

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

a = (0..2019)
	.lazy
	.find do |b|
		p = (2019+b).prime_division.to_h
		a = (l..r-1)
			.lazy
			.find do |i|
				q = i.prime_division.to_h.merge(p){|k,a,b|a-b}
				break if q.values.any?{|n|n>0} || !q.all?{|n|n==0}
				(i..r)
					.take(3)
					.lazy
					.find do |j|
						r = i.prime_division.to_h.merge(p, q){|k,a,b|a-b}
						break if r.all?{|n|n==0}
						true
					end
				true
			end
		b
	end
puts a