require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n,m = gets.chomp.split.map(&:to_i)

a = Array.new(n)

m.times do
  s, c = gets.chomp.split.map(&:to_i)

  if !a[s-1].nil? && a[s-1] != c
    puts -1
    exit
  end

  a[s-1] = c
end

n.times do |i|
  a[i] = 0 if a[i].nil?
end
ans = a.join('').to_i

if ans.to_s.size == n
  puts ans
else
  puts -1
end