n, m = gets.chomp.split(" ").map(&:to_i)
scs = m.times.map do
  s, c = gets.chomp.split(" ").map(&:to_i)
  [s, c]
end

h = {}
dupli = false

scs.each do |s, c|
  if h[s] && (h[s] != c)
    dupli = true
    break
  end

  h[s] = c
end

if dupli
  puts "-1"
  exit 0
end

str = ""

(1..n).each do |i|
  if h[i]
    str << h[i].to_s
  else
    if i == 1
      str << 1.to_s
    else
      str << 0.to_s
    end
  end
end

if str == "0"
  puts 0
elsif str[0] == "0"
  puts -1
else
  puts str
end
