N, M = gets.split.map(&:to_i)
scs = Array.new(M) { s, c = gets.chomp.split; [s.to_i.pred, c] }

min = 10 ** (N - 1)
max = 10 ** N - 1

rval = (min..max).find do |n|
  nc = n.to_s
  scs.all? do |s, c|
    nc[s] == c
  end
end

puts(rval ? rval : '-1')
