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)
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, True)

sty = SegmentTreeDual(N, min, 10**18, True)



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)
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)

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, True)
sty = SegmentTreeDual(N, min, 10**18, True)
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)

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