n = gets.to_i d = gets.split.map(&:to_i) x, y = gets.split.map(&:to_i) sum = x.abs + y.abs if x == 0 && y == 0 p 0 elsif d.include?(sum) p 1 else if sum % 2 == 0 if d.max * 2 >= sum p 2 else p -1 end else hoge = d.select{|x| x % 2 == 0} foo = d.select{|x| x % 2 == 1} if hoge.empty? || foo.empty? p -1 elsif hoge.max + foo.max >= sum p 2 else p -1 end end end