#N M
#s1 c1
#sM cM
#ちょうどN桁
#左から数えてsi桁目はci

N, M = gets.split.map(&:to_i)
s, c = M.times.map{gets.split.map(&:to_i)}.transpose
ans = [0, 0, 0]
chk = 0
M.times do |i|
  #puts s[i]
  if ans[s[i] - 1] == 0 || ans[s[i] - 1] == c[i]
    ans[s[i] -1] = c[i]
  else
    chk = -1
    break
  end
end
na = ans.join.to_i
if chk == -1 || na == 0
  puts "-1"
else
  puts na
end 