list = gets.split.map(&:to_i)
n , m = list[0], list[1]
result = []
(0...m).each do |i|
  _list = gets.split.map(&:to_i)
  result[i] = [_list[0], _list[1]]
end

error = false
ans = Array.new(n)

result.each do |arr|
  error = true if arr[0] == 1 && arr[1] == 0 && n != 1
  error = true if !ans[arr[0] - 1].nil? && ans[arr[0] - 1] != arr[1]
  error = true if arr[0] > m
  ans[arr[0] - 1] = arr[1]
end

ans[0] = 1 if ans[0].nil? && n != 1
puts error ? -1 : ans.map(&:to_i).map(&:to_s).inject(:+)