def main()
  ans = Array.new(N, -1)
  SC.each do |s, c|
    ss = s-1
    if ans[ss] == -1
      ans[ss] = c
    else
      return -1 if ans[ss] != c
    end
  end
  
  return -1 if ans[0] == 0 && N > 1
  
  if ans[0] == -1
    if N > 1
      ans[0] = 1 
    else
      ans[0] = 0
    end
  end
  
  1.upto(M-1) do |i|
    if ans[i] == -1
      ans[i] = 0
    end
  end
  
  return ans.join.to_i
end

N, M = gets.split.map(&:to_i)
SC = M.times.map{gets.split.map(&:to_i)}
p main
