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