# Original solution
class SegmentTreeDual():
    def __init__(self, arr, op=lambda x, y: y if y != -1 else x, ie=-1):
        self.h = (len(arr) - 1).bit_length()
        self.n = 2**self.h
        self.ie = ie
        self.op = op
        self.val = [ie for _ in range(self.n)]
        self.laz = [ie for _ in range(2 * self.n)]
        for i in range(len(arr)):
            self.val[i] = arr[i]

    def propagate(self, k):
        if self.laz[k] == self.ie: return
        if self.n <= k:
            self.val[k - self.n] = self.op(self.val[k - self.n], self.laz[k])
        else:
            self.laz[2 * k] = self.op(self.laz[2 * k], self.laz[k])
            self.laz[2 * k + 1] = self.op(self.laz[2 * k + 1], self.laz[k])
        self.laz[k] = self.ie

    def update(self, lt, rt, x):
        lt += self.n
        rt += self.n
        while rt - lt > 0:
            if lt & 1:
                self.laz[lt] = self.op(self.laz[lt], x)
                lt += 1
            if rt & 1:
                rt -= 1
                self.laz[rt] = self.op(self.laz[rt], x)
            lt >>= 1
            rt >>= 1

    def get(self, idx):
        res = self.val[idx]
        idx += self.n
        while idx:
            res = self.op(res, self.laz[idx])
            idx >>= 1
        return res

import sys
input = sys.stdin.buffer.readline

N, Q = list(map(int, input().split()))

x = [N - 1] * (N - 1) + [0]
y = [N - 1] * (N - 1) + [0]

stx = SegmentTreeDual(x, min, 10**18)
sty = SegmentTreeDual(y, min, 10**18)

res = (N - 2) * (N - 2)

for _ in range(Q):
    q, k = list(map(int, input().split()))
    if q == 1:
        g = stx.get(k - 1)
        res -= g - 1
        sty.update(1, g, k - 1)
    if q == 2:
        g = sty.get(k - 1)
        res -= g - 1
        stx.update(1, g, k - 1)

print(res)

# Optimized solution
class SegmentTreeDual():
    def __init__(self, n, op, id, commutative=False):
        self.n = n
        self.op = op
        self.id = id
        self.commutative = commutative
        self.log = (n - 1).bit_length()
        self.size = 1 << self.log
        self.d = [id] * self.size
        self.lz = [id] * (2 * self.size)

    def build(self, arr):
        for i, a in enumerate(arr):
            self.d[i] = a

    def propagate(self, k):
        if self.lz[k] == self.id: return
        if k < self.size:
            self.lz[2 * k] = self.op(self.lz[k], self.lz[2 * k], )
            self.lz[2 * k + 1] = self.op(self.lz[k], self.lz[2 * k + 1])
        else:
            self.d[k - self.size] = self.op(self.lz[k], self.d[k - self.size])
        self.lz[k] = self.id

    def get(self, p):
        res = self.d[p]
        p += self.size
        for i in range(self.log):
            res = self.op(self.lz[p >> i], res)
        return res

    def range_apply(self, l, r, f):
        if l == r: return
        l += self.size
        r += self.size
        if not self.commutative:
            for i in range(self.log)[::-1]:
                self.propagate(l >> i)
                self.propagate(r >> i)
        while l < r:
            if l & 1:
                self.lz[l] = self.op(f, self.lz[l])
                l += 1
            if r & 1:
                r -= 1
                self.lz[r] = self.op(f, self.lz[r])
            l >>= 1
            r >>= 1

import sys
input = sys.stdin.buffer.readline

N, Q = list(map(int, input().split()))

stx = SegmentTreeDual(N, min, 10**18, False)
sty = SegmentTreeDual(N, min, 10**18, False)

x = [N - 1] * (N - 1) + [0]
y = [N - 1] * (N - 1) + [0]

stx.build(x)
sty.build(y)

res = (N - 2) * (N - 2)

for _ in range(Q):
    q, k = list(map(int, input().split()))
    if q == 1:
        g = stx.get(k - 1)
        res -= g - 1
        sty.range_apply(1, g, k - 1)
    if q == 2:
        g = sty.get(k - 1)
        res -= g - 1
        stx.range_apply(1, g, k - 1)

print(res)