n, m = gets.split.map(&:to_i)
sc = m.times.map { gets.split.map(&:to_i) }

a = 'a' * n

sc.each do |e|
  s = e[0] - 1
  c = e[1].to_s
  if a[s] == 'a'
    a[s] = c
  elsif a[s] != c
    puts '-1'
    exit
  end
end

a.tr!('a', '0')
x = a.to_i.to_s

if x.size == n
  puts x
else
  puts '-1'
end
