N,M = gets.split.map(&:to_i)
SC = readlines.map {|s| s.split.map(&:to_i) }

ans = nil
num = Array.new(N,-1)
SC.each do |s,c|
  i = s - 1
  if num[i] != -1 && num[i] != c
    ans = -1
    break
  end
  num[i] = c
end
unless ans
  if num[0] == 0
    ans = -1
  else
    num[0] = 1 if num[0] < 0
    ans =  num.map {|n| n < 0 ? 0 : n }.join.to_i
  end
end
puts ans
