def foo
  n, m = gets.split.map(&:to_i)
  cs = []
  m.times do
    cs << gets.split.map(&:to_i)
  end
  a = "1" + "0"*(n-1)
  b = "9"*n

  (a..b).each do |str|
    return str if cs.all?{|s,c| str[s-1] == c.to_s}
  end

  return -1
end

puts foo()
