using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int n=s[0];
		St st1=new St(n+1,false);
		St st2=new St(n+1,false);
		st1.Ud2(1,n,n);
		st2.Ud2(1,n,n);
		long ans=0;
		for(int i = 0;i<s[1];i++) {
			var e=sc.Ia;
			if(e[0]==1){
				var g=(int)st1.Get(e[1]);
				ans+=g-2;
				st2.Ud2(1,g,e[1]);
			}
			else{
				var g=(int)st2.Get(e[1]);
				ans+=g-2;
				st1.Ud2(1,g,e[1]);
			}
		}
		Console.WriteLine("{0}",((long)n-2)*(n-2)-ans);
	}
}
public class St{
	private long[] dat;
	private int m=1,cnt,l=0;
	private long mv;
	private Func<long,long,long> Fm;
	public St(int n,bool mm){
		if(mm){mv=long.MinValue;Fm=Fmax;}
		else{mv=long.MaxValue;Fm=Fmin;}
		while(m<n){m<<=1;l++;}
		cnt=m+n-1;
		dat=new long[cnt];
		for(int i=0;i<cnt;i++){dat[i]=mv;}
	}
	private long Fmax(long a,long b){return Max(a,b);}
	private long Fmin(long a,long b){return Min(a,b);}
	public void Ud2(int a,int b,long d){Hn(a,b,0,0,m-1,d);}
	private void Hn(int a,int b,int k,int l,int r,long de){
		if(a<=l&&r<=b){dat[k]=Min(de,dat[k]);}
		else if(r>=a&&b>=l){
			if(dat[k]!=mv){
				dat[(k<<1)+1]=Fm(dat[k],dat[(k<<1)+1]);
				dat[(k<<1)+2]=Fm(dat[k],dat[(k<<1)+2]);
				dat[k]=mv;
			}
			Hn(a,b,(k<<1)+1,l,(l+r)>>1,de);
			Hn(a,b,(k<<1)+2,(l+r+1)>>1,r,de);
		}
	}
	public long Get(int a){
		int k=0,q=a+(1<<l);
		for(int i=l-1;i>=0;i--){
			if(dat[k]!=mv){
				dat[(k<<1)+1]=Fm(dat[k],dat[(k<<1)+1]);
				dat[(k<<1)+2]=Fm(dat[k],dat[(k<<1)+2]);
				dat[k]=mv;
			}
			k=(k<<1)+1+((q>>i)&1);
		}
		return dat[k]!=mv?dat[k]:0;
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 53440