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

ans = -1

range = if n == 0
  (0..9)
else
  (10 ** (n - 1)..((10 ** n) - 1))
end

range.each do |i|
  str = i.to_s.chars

  flag = conds.all? do |s, c|
    pos = s.to_i - 1
    str[pos] == c
  end

  if flag
    ans = i
    break
  end
end

puts(ans)
