a=3.times.map{gets.split.map(&:to_i)} p (0..1e6).find{|i|a.all?{|x,y|i%y==x}}