n, m = gets.split.map(&:to_i)
s = []
c = []
for i in 0..m-1
  a, b = gets.split.map(&:to_i)
  s << a
  c << b
end
ans = -1
for k in 1..999
  next if k.to_s.length != n
  flag = true
  s.each_with_index do |si, i|
    if k.to_s[si-1] != c[i].to_s
      flag = false
    end
  end
  if flag
    ans = k
    break
  end
end
puts ans
