# n: 桁数
n, m = read_line.split.map(&.to_i64)
sc = Array.new(n) { read_line.split.map(&.to_i64) }.uniq

numbers = (10 ** (n-1)).upto(10 ** n - 1).to_a

def valid?(number, sc)
  number_as_string = number.to_s
  sc.all? { |sc_pair|
    s, c = sc_pair
    number_as_string[s - 1].to_s == c.to_s
  }
end

candidates = numbers.select do |number|
  valid?(number, sc)
end

if candidates.size == 0
  puts "-1"
else
  puts candidates.sort.first
end
