n, q = gets.chomp.split(" ").map(&:to_i)                                                                                               
                                                                                                                                       
h_line = []                                                                                                                            
v_line = []                                                                                                                            
                                                                                                                                       
q.times do |l|                                                                                                                         
  line_type, line_num = gets.chomp.split(" ").map(&:to_i)                                                                              
  target_arr = line_type == 1 ? h_line : v_line                                                                                        
  alt_arr = line_type == 1 ? v_line : h_line                                                                                           
                                                                                                                                       
  closest = 0                                                                                                                          
  reverse_count = 0                                                                                                                    
  target_arr.each do |old|                                                                                                             
    next if old[0] > line_num                                                                                                          
    next if old[0] < closest                                                                                                           
    closest = old[0]                                                                                                                   
    reverse_count = old[1]                                                                                                             
  end                                                                                                                                  
  if closest == 0                                                                                                                      
    reverse_count = alt_arr.empty? ? n-2 : alt_arr.map{|a| a[0]}.min - 2                                                               
  end                                                                                                                                  
  target_arr << [line_num, reverse_count]                                                                                              
end                                                                                                                                    
reverse_total = h_line.map{|a| a[1]}.sum + v_line.map{|a| a[1]}.sum                                                                    
                                                                                                                                       
print (n-2)**2 - reverse_total    