N, M = gets.chomp.split.map(&:to_i)

ans = Array.new(N, 0)
digit = Hash.new{ |k, v| k[v] = []}
M.times do
  s, c = gets.chomp.split.map(&:to_i)
  s -= 1
  
  if N >= 2 and s >= 2 and c.zero?
    p -1
    exit
  end
  
  digit[s].push(c).uniq!
  if digit[s].length >= 2
    p -1
    exit
  else
    ans[s] = c
  end
end

p ans.join.to_i