N,Q = gets.split.map(&:to_i)
bk = (N-2)**2
bb = [0]*(N-1),[0]*(N-1)
ii = [0,0]
Q.times{
	b,x = gets.split.map(&:to_i).then{|b,x| [b-1,N-x] }
	y = x < ii[b] ? bb[b][x] : ii[b-1]
	bk -= N-2-y
	if ii[b] < x
		bb[b].fill(y,ii[b]+1..x)
		ii[b] = x
	end
}
p bk
