n, m = gets.chomp.split.map(&:to_i)

res = Array.new(n, 0)
visited = Array.new(n, false)

m.times do
  s, c = gets.chomp.split.map(&:to_i)
  if visited[s - 1] && res[s - 1] != c
    puts "-1"
    exit
  end
  visited[s - 1] = true
  res[s - 1] = c
end

if visited[0] && res[0] == 0
  puts "-1"
  exit
end

if !visited[0]
  res[0] = 1
end
puts res.join("")