N, M = gets.split.map(&:to_i)

if M == 0
  print(-1)
  exit
end

from = 10**(N - 1)
to = (10**N) - 1

check = M.times.to_a.map do
  gets.split.map(&:to_i)
end

check.sort! do |l, r|
  if l[0] == r[0]
    l[1] <=> r[1]
  else
    l[0] <=> r[0]
  end
end

check.uniq! { |s| [s[0], s[1]] }
if check.size != check.uniq { |s| s[0] }
  print(-1)
  exit
end

from.upto(to) do |i|
  s = i.to_s
  c = check.all? do |v|
    s[v[0] - 1].to_i == v[1]
  end
  if c
    print i
    exit
  end
end

print(-1)
