#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, q) = (v[0], v[1]);
    let mut queries = vec![];
    for i in 0..q {
        let v = read_vec::<usize>();
        queries.push((v[0] - 1, v[1] - 2));
    }

    let mut segs = vec![LazySegmentTree::new(n - 1); 2];
    for j in 0..2 {
        segs[j].update(0, n - 1, n as i64 - 2, 0, 0, n - 1);
    }

    let mut changed = 0;
    for (i, (axis, x)) in queries.into_iter().enumerate() {
        let temp_changed = segs[axis].getmin(x, x + 1, 0, 0, n - 1);
        changed += temp_changed;
        segs[1 - axis].update(0, temp_changed as usize, x as i64, 0, 0, n - 1);
    }
    let ans = (n as i64 - 2) * (n as i64 - 2) - changed;
    println!("{}", ans);
}

use std::cmp::*;

const INF: i64 = 1001001001001001;

#[derive(Debug, Clone)]
struct LazySegmentTree {
    n: usize,
    node: Vec<i64>,
    lazy: Vec<i64>,
}

impl LazySegmentTree {
    fn new(sz: usize) -> LazySegmentTree {
        let mut n = 1;
        while n < sz {
            n *= 2;
        }
        LazySegmentTree {
            n: n,
            node: vec![INF; n * 2],
            lazy: vec![INF; n * 2],
        }
    }

    fn eval(&mut self, k: usize, l: usize, r: usize) {
        if self.lazy[k] != INF {
            self.node[k] = min(self.node[k], self.lazy[k]);
            if r - l > 1 {
                self.lazy[2 * k + 1] = min(self.lazy[2 * k + 1], self.lazy[k]);
                self.lazy[2 * k + 2] = min(self.lazy[2 * k + 2], self.lazy[k]);
            }
            self.lazy[k] = INF;
        }
    }

    fn update(&mut self, a: usize, b: usize, x: i64, k: usize, l: usize, r: usize) {
        // update [l, r) k = 0, l = 0, r = n is default
        self.eval(k, l, r);

        // if out of range, do nothing.
        if b <= l || r <= a {
            return;
        }

        if a <= l && r <= b {
            self.lazy[k] = min(self.lazy[k], x);
            self.eval(k, l, r);
        } else {
            self.update(a, b, x, 2 * k + 1, l, (l + r) / 2);
            self.update(a, b, x, 2 * k + 2, (l + r) / 2, r);
            self.node[k] = min(self.node[2 * k + 1], self.node[2 * k + 2]);
        }
    }

    fn getmin(&mut self, a: usize, b: usize, k: usize, l: usize, r: usize) -> i64 {
        if b <= l || r <= a {
            return INF;
        }

        self.eval(k, l, r);
        if a <= l && r <= b {
            return self.node[k];
        }

        min(
            self.getmin(a, b, 2 * k + 1, l, (l + r) / 2),
            self.getmin(a, b, 2 * k + 2, (l + r) / 2, r),
        )
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 21588