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

ans = Array.new(n) { nil }
flag = false

conds.each do |s, c|
  i = s.to_i - 1
  if ans[i].nil?
    ans[i] = c
  elsif ans[i] != c
    flag = true
  end
end

ans = ans.map do |c|
  if c.nil?
    "0"
  else
    c
  end
end

if flag
  puts(-1)
else
  a = ans.join('')
  if a.to_i.to_s.length == n
    puts(a.to_i)
  else
    puts(-1)
  end
end
