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)
  str[s[i]-1] = []
  str[s[i]-1] << c[i]
end

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

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