require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n,q = gets.chomp.split.map(&:to_i)

ans = 0
tate = Hash.new
yoko = Hash.new
tatekeys = []
yokokeys = []
q.times do
  val, x = gets.chomp.split.map(&:to_i)
  if val == 1
    key = tatekeys.bsearch{|y| y >= x}
    val = tate[key] || n - 1
    unless yoko.has_key? val
      yoko[val] = x - 1
      yokokeys.unshift val
    end
  else
    key = yokokeys.bsearch{|y| y >= x}
    val = yoko[key] || n - 1
    unless tate.has_key? val
      tate[val] ||= x - 1
      tatekeys.unshift val
    end
  end
  val -= 1
  ans += val
  # p [tate, yoko, val]
end

p (n-2)**2 - ans
