def extgcd(a, b) if b.zero? {x: 1, y: 0, gcd: a} else prev = extgcd(b, a % b) { x: prev[:y], y: prev[:x] - (a / b) * prev[:y], gcd: prev[:gcd] } end end def mod_inv(a,m) res = extgcd(a,m) x = res[:x] return (m+x%m)%m end def linear_congruence(as,bs,ms) x,m = 0,1 as.size.times do |i| a = as[i]*m b = bs[i] - as[i] * x d = ms[i].gcd(a) return if b % d != 0 tt = b/d * mod_inv(a/d, ms[i]/d) % (ms[i]/d) x = x + m*tt m *= ms[i]/d end return [x%m, m] end n = gets.to_i t = [] n.times do x,y = gets.chomp.split.map(&:to_i) t << [x,y] end xs,ys = t.transpose as = [1] * n mod = 1000000007 ans = linear_congruence(as,xs,ys) puts ->(x){ if x.nil? -1 elsif ans[0] == 0 ans[1] % mod else ans[0] % mod end }.call(ans)