use proconio::input;

const INF: usize = (1 << 31) - 1;

fn main() {
    input! {
        n: usize,
        q: usize,
    }
    let n = n - 2;
    let mut queries = vec![];
    for _ in 0..q {
        input! {
            t: usize,
            x: usize,
        }
        if t == 1 {
            queries.push(Query::Vertical(x - 2))
        } else {
            queries.push(Query::Horizontal(x - 2))
        }
    }

    let mut v_tree = SegmentTree::build(&vec![INF; n], std::cmp::min, INF);
    let mut h_tree = SegmentTree::build(&vec![INF; n], std::cmp::min, INF);
    v_tree.update(n - 1, n);
    h_tree.update(n - 1, n);

    let mut ans = n * n;
    for query in queries {
        match query {
            Query::Vertical(x) => {
                let a = h_tree.query(x, n);
                // dbg!("v", x, a);
                if a >= 1 && x < v_tree.query(a - 1, a) {
                    v_tree.update(a - 1, x);
                }
                // eprintln!("update v: ({}, {})", a, x);
                ans -= a;
            }
            Query::Horizontal(x) => {
                let a = v_tree.query(x, n);
                // dbg!("h", x, a);
                if a >= 1 && x < h_tree.query(a - 1, a) {
                    h_tree.update(a - 1, x);
                }
                // eprintln!("update h: ({}, {})", a, x);
                ans -= a;
            }
        }
        // dbg!(ans);
    }
    println!("{}", ans);
}

enum Query {
    Vertical(usize),
    Horizontal(usize),
}

struct SegmentTree<T, F>
where
    F: Fn(T, T) -> T,
    T: Clone + Copy,
{
    len: usize,
    data: Vec<T>,
    operator: F,
    unit: T,
}

impl<T, F> SegmentTree<T, F>
where
    F: Fn(T, T) -> T,
    T: Clone + Copy,
{
    fn build(v: &Vec<T>, operator: F, unit: T) -> SegmentTree<T, F> {
        let n = v.len();
        let mut len = 1;
        while len < n {
            len *= 2;
        }

        let mut segtree = SegmentTree {
            len,
            data: vec![unit; 2 * len - 1],
            operator,
            unit,
        };

        for i in 0..n {
            segtree.data[i + segtree.len - 1] = v[i];
        }
        for i in (0..(segtree.len - 1)).rev() {
            segtree.data[i] = (segtree.operator)(segtree.data[2 * i + 1], segtree.data[2 * i + 2]);
        }

        segtree
    }

    #[allow(unused)]
    fn update(&mut self, k: usize, a: T) {
        let data = &mut self.data;
        let mut k = k + self.len - 1;
        data[k] = a;
        while k > 0 {
            k = (k - 1) / 2;
            data[k] = (self.operator)(data[k * 2 + 1], data[k * 2 + 2]);
        }
    }

    #[allow(unused)]
    fn get(&self, k: usize) -> T {
        self.data[k + self.len - 1]
    }

    fn query(&self, a: usize, b: usize) -> T {
        self.execute_query(a, b, 0, 0, self.len)
    }

    fn execute_query(&self, a: usize, b: usize, k: usize, l: usize, r: usize) -> T {
        if r <= a || b <= l {
            return self.unit;
        }

        if a <= l && r <= b {
            self.data[k]
        } else {
            let vl = self.execute_query(a, b, k * 2 + 1, l, (l + r) / 2);
            let vr = self.execute_query(a, b, k * 2 + 2, (l + r) / 2, r);
            (self.operator)(vl, vr)
        }
    }
}


Measured memory_bytes: 16592