N, M = gets.split.map(&:to_i)
s = []
c = []
str = Hash.new
M.times do |i|
  s[i], c[i] = gets.split.map(&:to_i)
  if str[s[i]-1].nil?
    str[s[i]-1] = []
  end
  str[s[i]-1] << c[i]
end

# puts "#{str}"

ans = []
ans = ans.fill('0',0..N-1)
if N>=2
  ans[0] = '1'
end

str.each do |key, val|
  if key==0 and val.first==0 and N>=2
    puts -1
    exit!
  end
  val.uniq!
  if val.size >= 2
    puts -1
    exit!
  end
  ans[key] = val.first.to_s
end
puts "#{ans.inject(:+)}"

# str.each do |key, val|
#   if key==0 and val.first==0 and N>=2
#     puts -1
#     exit
#   else
#     val.uniq!
#     if val.size >= 2
#       puts -1
#       exit
#     else
#       ans[key] = val.first.to_s
#     end
#   end
# end
# puts "#{ans.inject(:+)}"