N,M = gets.split.map(&:to_i)
D = Array.new(N + 1)
fail = M.times.find do
  s,d = gets.split.map(&:to_i)
  if s == 1 && d == 0
    true
  elsif !D[s] || (D[s] == d)
    D[s] = d
    false
  else
    true
  end
end
if fail
  puts -1
else
  ans = (1 .. N).inject(0) do |s,n|
    if D[n]
      s * 10 + D[n]
    else
      s * 10 + (n == 1 ? 1 : 0)
    end
  end
  puts ans
end