fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: i64 = s.next().unwrap().parse().unwrap();
	let q: usize = s.next().unwrap().parse().unwrap();
	let mut ans = (n - 2) * (n - 2);
	let mut left = LazySegmentTree::new(
		n as usize,
		std::i64::MAX,
		|a, b| std::cmp::min(a, b),
		|a, b| std::cmp::min(a, b),
		|a, b| std::cmp::min(a, b),
	);
	left.operate(0, n as usize, n - 1);
	let mut top = LazySegmentTree::new(
		n as usize,
		std::i64::MAX,
		|a, b| std::cmp::min(a, b),
		|a, b| std::cmp::min(a, b),
		|a, b| std::cmp::min(a, b),
	);
	top.operate(0, n as usize, n - 1);
	for _ in 0..q {
		let ty = s.next().unwrap();
		if ty == "1" {
			let x: usize = s.next().unwrap().parse().unwrap();
			let x = x - 1;
			let t = top.get(x).unwrap();
			ans -= t - 1;
			left.operate(0, t as usize, x as i64);
		} else {
			let y: usize = s.next().unwrap().parse().unwrap();
			let y = y - 1;
			let l = left.get(y).unwrap();
			ans -= l - 1;
			top.operate(0, l as usize, y as i64);
		}
	}
	println!("{}", ans);
}

pub struct LazySegmentTree<M, P, F, G, H> {
	n: usize,
	data: Vec<M>,
	cache: Vec<Option<P>>,
	e: M,
	mfold: F,
	op: G,
	opfold: H,
}

impl<M, P, F, G, H> LazySegmentTree<M, P, F, G, H>
where
	M: Clone,
	P: Clone,
	F: Fn(M, M) -> M,
	G: Fn(M, P) -> M,
	H: Fn(P, P) -> P,
{
	pub fn new(n: usize, e: M, mfold: F, op: G, opfold: H) -> Self {
		Self {
			n,
			data: vec![e.clone(); 2 * n],
			cache: vec![None; 2 * n],
			e,
			mfold,
			op,
			opfold,
		}
	}

	pub fn construct(src: Vec<M>, e: M, mfold: F, op: G, opfold: H) -> Self {
		let mut data = vec![e.clone(); src.len()];
		data.extend(src);
		for i in (1..data.len() / 2).rev() {
			data[i] = mfold(data[i << 1].clone(), data[i << 1 | 1].clone());
		}
		let cache = vec![None; data.len()];
		Self {
			n: data.len() / 2,
			data,
			cache,
			e,
			mfold,
			op,
			opfold,
		}
	}

	fn from_ancestors(&mut self, i: usize) {
		let log2 = (i + 1).next_power_of_two().trailing_zeros() - 1;
		for j in (1..=log2).rev() {
			let i = i >> j;
			if let Some(p) = self.cache[i].take() {
				self.data[i] = (self.op)(self.data[i].clone(), p.clone());
				if let Some(child) = self.cache[i << 1].take() {
					self.cache[i << 1] = Some((self.opfold)(child, p.clone()));
				} else {
					self.cache[i << 1] = Some(p.clone());
				}
				if let Some(child) = self.cache[i << 1 | 1].take() {
					self.cache[i << 1 | 1] = Some((self.opfold)(child, p.clone()));
				} else {
					self.cache[i << 1 | 1] = Some(p.clone());
				}
			}
		}
	}

	fn to_ancestors(&mut self, mut i: usize) {
		while {
			i >>= 1;
			i > 0
		} {
			let s = self.operate_at(i << 1);
			let t = self.operate_at(i << 1 | 1);
			self.data[i] = (self.mfold)(s, t);
		}
	}

	fn operate_at(&self, i: usize) -> M {
		if let Some(p) = self.cache[i].as_ref() {
			(self.op)(self.data[i].clone(), p.clone())
		} else {
			self.data[i].clone()
		}
	}

	pub fn operate(&mut self, l: usize, r: usize, x: P) {
		let mut l = l + self.n;
		let mut r = r + self.n;
		let ltop = l >> l.trailing_zeros();
		let rtop = r >> r.trailing_zeros();
		self.from_ancestors(ltop);
		self.from_ancestors(rtop);
		while l < r {
			if l & 1 != 0 {
				if let Some(p) = self.cache[l].take() {
					self.cache[l] = Some((self.opfold)(p, x.clone()));
				} else {
					self.cache[l] = Some(x.clone());
				}
				l += 1;
			}
			if r & 1 != 0 {
				if let Some(p) = self.cache[r - 1].take() {
					self.cache[r - 1] = Some((self.opfold)(p, x.clone()));
				} else {
					self.cache[r - 1] = Some(x.clone());
				}
			}
			l >>= 1;
			r >>= 1;
		}
		self.to_ancestors(ltop);
		self.to_ancestors(rtop);
	}

	pub fn fold(&mut self, l: usize, r: usize) -> M {
		let mut l = l + self.n;
		let mut r = r + self.n;
		let ltop = l >> l.trailing_zeros();
		let rtop = r >> r.trailing_zeros();
		self.from_ancestors(ltop);
		self.from_ancestors(rtop);
		let mut s = self.e.clone();
		let mut t = self.e.clone();
		while l < r {
			if l & 1 != 0 {
				s = (self.mfold)(s, self.operate_at(l));
				l += 1;
			}
			if r & 1 != 0 {
				t = (self.mfold)(self.operate_at(r - 1), t);
			}
			l >>= 1;
			r >>= 1;
		}
		(self.mfold)(s, t)
	}

	pub fn get(&mut self, i: usize) -> Option<M> {
		if i < self.n {
			Some(self.fold(i, i + 1))
		} else {
			None
		}
	}

	pub fn set(&mut self, i: usize, x: M) {
		let i = i + self.n;
		self.from_ancestors(i);
		self.data[i] = x;
		self.cache[i] = None;
		self.to_ancestors(i);
	}

	pub fn len(&self) -> usize {
		self.n
	}
}


Measured memory_bytes: 22432