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





class SegmentTree:

    def __init__(self, init_value: list, segfunc, ide_ele):

        n = len(init_value)

        self.N0 = 1 << (n - 1).bit_length()

        self.ide_ele = ide_ele

        self.data = [ide_ele] * (2 * self.N0)

        self.segfunc = segfunc

        

        for i, x in enumerate(init_value):

            self.data[i + self.N0 - 1] = x

        for i in range(self.N0 - 2, -1, -1):

            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])

    

    # k: index , x: value

    def update(self, k: int, x):

        k += self.N0 - 1

        ############################

        self.data[k] = x

        ###########################

        while k:

            k = (k - 1) // 2

            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])



    def get(self, k):

        return self.query(k,k+1)

    

    # rightは開区間  l<=x<r

    def query(self, left: int, right: int):

        L = left + self.N0

        R = right + self.N0

        res = self.ide_ele

        ##########################

        a, b = [], []

        while L < R:

            if L & 1:

                a.append(L - 1)

                L += 1

            if R & 1:

                R -= 1

                b.append(R - 1)

            L >>= 1

            R >>= 1

        for i in a + b[::-1]:

            res = self.segfunc(res, self.data[i])

        ##########################

        return res







"""

     .

 ####.

 ####.

 ####.

 ####.

......



"""

#到達したところまでをxに変える



segW=SegmentTree([N-2]*N, min, 10**18)

segH=SegmentTree([N-2]*N, min, 10**18)

ans=(N-2)**2

for i in range(Q):

    q,x=list(map(int, input().split()))

    if q==1:

        res=segW.query(x-1,N)

        #now=segH.get(res-1)

        segH.update(res, min(x-2, segH.query(res,N)))

        ans-=res

    else:

        res=segH.query(x-1,N)

        now=segW.get(res-1)

        segW.update(res, min(x-2, segW.query(res,N)))

        ans-=res

    #print(res, ans, res-1, x-1, q[0])





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





class SegmentTree:

    def __init__(self, init_value: list, segfunc, ide_ele):

        n = len(init_value)

        self.N0 = 1 << (n - 1).bit_length()

        self.ide_ele = ide_ele

        self.data = [ide_ele] * (2 * self.N0)

        self.segfunc = segfunc

        

        for i, x in enumerate(init_value):

            self.data[i + self.N0 - 1] = x

        for i in range(self.N0 - 2, -1, -1):

            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])

    

    # k: index , x: value

    def update(self, k: int, x):

        k += self.N0 - 1

        ############################

        self.data[k] = x

        ###########################

        while k:

            k = (k - 1) // 2

            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])



    def get(self, k):

        return self.query(k,k+1)

    

    # rightは開区間  l<=x<r

    def query(self, left: int, right: int):

        L = left + self.N0

        R = right + self.N0

        res = self.ide_ele

        ##########################

        a, b = [], []

        while L < R:

            if L & 1:

                a.append(L - 1)

                L += 1

            if R & 1:

                R -= 1

                b.append(R - 1)

            L >>= 1

            R >>= 1

        for i in a + b[::-1]:

            res = self.segfunc(res, self.data[i])

        ##########################

        return res







"""

     .

 ####.

 ####.

 ####.

 ####.

......



"""

#到達したところまでをxに変える



segW=SegmentTree([N-1]*N, min, float("INF"))

segH=SegmentTree([N-1]*N, min, float("INF"))

ans=(N-2)**2

for i in range(Q):

    q,x=list(map(int, input().split()))

    if q==1:

        res=segW.query(x-1,N)

        now=segH.get(res-1)

        segH.update(res-1, min(x-1, now))

        ans-=max(res-1,0)

    else:

        res=segH.query(x-1,N)

        now=segW.get(res-1)

        segW.update(res-1, min(x-1, now))

        ans-=max(res-1,0)

    #print(res, ans, res-1, x-1, q[0])





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


class SegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])

    # k: index , x: value
    def update(self, k: int, x):
        k += self.N0 - 1
        ############################
        self.data[k] = x
        ###########################
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])

    def get(self, k):
        return self.query(k, k + 1)

    # rightは開区間  l<=x<r
    def query(self, left: int, right: int):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ##########################
        a, b = [], []
        while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
        for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ##########################
        return res


"""
     .
 ####.
 ####.
 ####.
 ####.
......
"""
# 到達したところまでをxに変える
segW = SegmentTree([N - 2] * N, min, 10**18)
segH = SegmentTree([N - 2] * N, min, 10**18)
ans = (N - 2) ** 2
for i in range(Q):
    q, x = list(map(int, input().split()))
    if q == 1:
        res = segW.query(x - 1, N)
        # now=segH.get(res-1)
        segH.update(res, min(x - 2, segH.query(res, N)))
        ans -= res
    else:
        res = segH.query(x - 1, N)
        now = segW.get(res - 1)
        segW.update(res, min(x - 2, segW.query(res, N)))
        ans -= res
    # print(res, ans, res-1, x-1, q[0])
print(ans)

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


class SegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])

    # k: index , x: value
    def update(self, k: int, x):
        k += self.N0 - 1
        ############################
        self.data[k] = x
        ###########################
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])

    def get(self, k):
        return self.query(k, k + 1)

    # rightは開区間  l<=x<r
    def query(self, left: int, right: int):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ##########################
        a, b = [], []
        while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
        for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ##########################
        return res


"""
     .
 ####.
 ####.
 ####.
 ####.
......
"""
# 到達したところまでをxに変える
segW = SegmentTree([N - 1] * N, min, float("INF"))
segH = SegmentTree([N - 1] * N, min, float("INF"))
ans = (N - 2) ** 2
for i in range(Q):
    q, x = list(map(int, input().split()))
    if q == 1:
        res = segW.query(x - 1, N)
        now = segH.get(res - 1)
        segH.update(res - 1, min(x - 1, now))
        ans -= max(res - 1, 0)
    else:
        res = segH.query(x - 1, N)
        now = segW.get(res - 1)
        segW.update(res - 1, min(x - 1, now))
        ans -= max(res - 1, 0)
    # print(res, ans, res-1, x-1, q[0])
print(ans)

-segW = SegmentTree([N - 2] * N, min, 10**18) -segH = SegmentTree([N - 2] * N, min, 10**18) +segW = SegmentTree([N - 1] * N, min, float("INF")) +segH = SegmentTree([N - 1] * N, min, float("INF")) -        # now=segH.get(res-1) -        segH.update(res, min(x - 2, segH.query(res, N))) -        ans -= res +        now = segH.get(res - 1) +        segH.update(res - 1, min(x - 1, now)) +        ans -= max(res - 1, 0) -        segW.update(res, min(x - 2, segW.query(res, N))) -        ans -= res +        segW.update(res - 1, min(x - 1, now)) +        ans -= max(res - 1, 0)