require 'set'

N, M = gets.split.map(&:to_i)
guess = [Set.new, Set.new, Set.new]
M.times do
  s, c = gets.split.map(&:to_i)
  guess[s - 1] << c
end

guess.each do |c|
  if c.length > 1
    puts '-1'
    exit
  end
end

if N == 3
  if guess[0].empty?
    guess[0] << 1
  end
  if guess[1].empty?
    guess[1] << 0
  end
  if guess[2].empty?
    guess[2] << 0
  end
elsif N == 2
  if guess[1].empty?
    guess[1] << 1
  end
  if guess[2].empty?
    guess[2] << 0
  end
else
  if guess[2].empty?
    guess[2] << 0
  end
end

if guess.map(&:first).join.to_i.to_s.length == N
  puts guess.map(&:first).join.to_i
else
  puts '-1'
end