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

if N < M
  puts -1
  exit
end

# puts "#{str}"

ans = []
ans = ans.fill('0',0..N-1)

flag = false
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
  if key == 0
    flag = true
  end
end
if not flag
  ans[0] = '1'
end
puts "#{ans.inject(:+)}"

