r = -1
N,M = gets.split.map(&:to_i)
si = []
sc = {}
M.times do |i|
  si.push(gets.chomp.split.map(&:to_i))
  if sc[si[i][0]]
    sc[si[i][0]] = si[i][1] if sc[si[i][0]] > si[i][1]
  else
    sc[si[i][0]] = si[i][1]
  end
end
a = 0
sc.each{|s,c|
  a += 10 ** (M-s) * c
}
if a.to_s.length == N
  r = a
end
puts r