N,Q=gets.split.map(&:to_i)
X=[[0,N-3,N-2]]
Y=[[0,N-3,N-2]]
Q.times{
	q,x=gets.split.map(&:to_i)
	x-=2
	case q
	when 1
		i=X.bsearch_index{|o|o[1]>=x}
		next unless i
		if i==0
			if x==0
				Y.shift
			else
				Y[0][2]=x
			end
		end
		if X[i][0]==x
			if X[i][0]==X[i][1]
				X.delete_at(i)
			else
				X[i][0]=x+1
			end
		elsif X[i][1]==x
			X[i][1]=x-1
		else
			c=[x+1,X[i][1],X[i][2]]
			X.insert(i+1,c)
			X[i][1]=x-1
		end
	when 2
		i=Y.bsearch_index{|o|o[1]>=x}
		next unless i
		if i==0
			if x==0
				X.shift
			else
				X[0][2]=x
			end
		end
		if Y[i][0]==x
			if Y[i][0]==Y[i][1]
				Y.delete_at(i)
			else
				Y[i][0]=x+1
			end
		elsif Y[i][1]==x
			Y[i][1]=x-1
		else
			c=[x+1,Y[i][1],Y[i][2]]
			Y.insert(i+1,c)
			Y[i][1]=x-1
		end
	end
	#warn X.inspect
	#warn Y.inspect
}
r=0
r+=X.inject(0){|r,i|r+(i[1]-i[0]+1)*i[2]}
if Y[0][0]==0
	Y.shift
end
r+=Y.inject(0){|r,i|r+(i[1]-i[0]+1)*i[2]}
puts r
