n = int(input())
a = [int(item) for item in input().split()]
#
# def gcd(a, b):
#     while b:
#         a, b = b, a % b
#     return a
#
# start = -1
# for i in range(n):
#     cur = a[i]
#     if cur / 2
#     for j in range(n):
#         if j == i: continue
#         for k in range(n - 1):
#             p = n - 1 - k
#             if (1 << p) == a[j] / gcd(a[i], a[j]) and (3^k) == a[i] / gcd(a[i], a[j]):
#                 break
#         else:
#             break
#     else:
#         continue
#     start = i
#     break
#

def solve(start, occ, d):
    #print(occ)
    if d == n - 1:
        return True
    u = False
    v = False
    if start // 3 == start / 3 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] = 0
        u = solve(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] = 0
        v = solve(start * 2, new_occ, d + 1)

    return u or v

def solve2(start, occ, d):

    if d == n - 1:
        return True, [start]
    u = False, []
    v = False, []
    if start // 3 == start / 3 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] = 0
        u = solve2(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] = 0
        v = solve2(start * 2, new_occ, d + 1)

    if u[0]:
        return True, [start] + u[1]
    if v[0]:
        return True, [start] + v[1]

    return False, []

occ = {key: 0 for key in a}

for i in range(n):
    occ[a[i]] += 1

for i in range(n):
    new_occ = dict(occ)
    new_occ[a[i]] -= 1
    if solve(a[i], new_occ, 0):
        new_occ = dict(occ)
        new_occ[a[i]] -= 1
        print(" ".join(str(item) for item in solve2(a[i], new_occ, 0)[1]))
        break


n = int(input())
a = [int(item) for item in input().split()]
#
# def gcd(a, b):
#     while b:
#         a, b = b, a % b
#     return a
#
# start = -1
# for i in range(n):
#     cur = a[i]
#     if cur / 2
#     for j in range(n):
#         if j == i: continue
#         for k in range(n - 1):
#             p = n - 1 - k
#             if (1 << p) == a[j] / gcd(a[i], a[j]) and (3^k) == a[i] / gcd(a[i], a[j]):
#                 break
#         else:
#             break
#     else:
#         continue
#     start = i
#     break
#

def solve(start, occ, d):
    #print(occ)
    if d == n - 1:
        return True
    u = False
    v = False
    if start % 3 == 0 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] = 0
        u = solve(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] = 0
        v = solve(start * 2, new_occ, d + 1)

    return u or v

def solve2(start, occ, d):

    if d == n - 1:
        return True, [start]
    u = False, []
    v = False, []
    if start % 3 == 0 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] = 0
        u = solve2(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] = 0
        v = solve2(start * 2, new_occ, d + 1)

    if u[0]:
        return True, [start] + u[1]
    if v[0]:
        return True, [start] + v[1]

    return False, []

occ = {key: 0 for key in a}

for i in range(n):
    occ[a[i]] += 1

for i in range(n):
    new_occ = dict(occ)
    new_occ[a[i]] -= 1
    if solve(a[i], new_occ, 0):
        new_occ = dict(occ)
        new_occ[a[i]] -= 1
        print(" ".join(str(item) for item in solve2(a[i], new_occ, 0)[1]))
        break


n = int(input())
a = [int(item) for item in input().split()]
#
# def gcd(a, b):
#     while b:
#         a, b = b, a % b
#     return a
#
# start = -1
# for i in range(n):
#     cur = a[i]
#     if cur / 2
#     for j in range(n):
#         if j == i: continue
#         for k in range(n - 1):
#             p = n - 1 - k
#             if (1 << p) == a[j] / gcd(a[i], a[j]) and (3^k) == a[i] / gcd(a[i], a[j]):
#                 break
#         else:
#             break
#     else:
#         continue
#     start = i
#     break
#
ind = {}
for i in range(n):
    ind[a[i]] = i

def solve(start, occ, d):
    if d == n - 1:
        return True
    u = False
    v = False
    if start / 3 == start // 3 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] -= 1
        u = solve(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] -= 1
        v = solve(start * 2, new_occ, d + 1)

    return u or v

def solve2(start, occ, d):

    if d == n - 1:
        return True, [start]
    u = False, []
    v = False, []
    if start / 3 == start // 3 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] -= 1
        u = solve2(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] -= 1
        v = solve2(start * 2, new_occ, d + 1)

    if u[0]:
        return True, [start] + u[1]
    if v[0]:
        return True, [start] + v[1]

    return False, []

occ = {key: 0 for key in a}

for i in range(n):
    occ[a[i]] += 1

for i in range(n):
    if solve(a[i], occ, 0):
        print(" ".join(str(item) for item in solve2(a[i], occ, 0)[1]))
        break


n = int(input())
a = [int(item) for item in input().split()]
#
# def gcd(a, b):
#     while b:
#         a, b = b, a % b
#     return a
#
# start = -1
# for i in range(n):
#     cur = a[i]
#     if cur / 2
#     for j in range(n):
#         if j == i: continue
#         for k in range(n - 1):
#             p = n - 1 - k
#             if (1 << p) == a[j] / gcd(a[i], a[j]) and (3^k) == a[i] / gcd(a[i], a[j]):
#                 break
#         else:
#             break
#     else:
#         continue
#     start = i
#     break
#

def solve(start, occ, d):
    #print(occ)
    if d == n - 1:
        return True
    u = False
    v = False
    if start / 3 == start // 3 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] -= 1
        u = solve(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] -= 1
        v = solve(start * 2, new_occ, d + 1)

    return u or v

def solve2(start, occ, d):

    if d == n - 1:
        return True, [start]
    u = False, []
    v = False, []
    if start / 3 == start // 3 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] -= 1
        u = solve2(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] -= 1
        v = solve2(start * 2, new_occ, d + 1)

    if u[0]:
        return True, [start] + u[1]
    if v[0]:
        return True, [start] + v[1]

    return False, []

occ = {key: 0 for key in a}

for i in range(n):
    occ[a[i]] += 1

for i in range(n):
    new_occ = dict(occ)
    new_occ[a[i]] -= 1
    if solve(a[i], new_occ, 0):
        new_occ = dict(occ)
        new_occ[a[i]] -= 1
        print(" ".join(str(item) for item in solve2(a[i], new_occ, 0)[1]))
        break
else:
    x = []
    x[0] = 1


n = int(input())
a = [int(item) for item in input().split()]
#
# def gcd(a, b):
#     while b:
#         a, b = b, a % b
#     return a
#
# start = -1
# for i in range(n):
#     cur = a[i]
#     if cur / 2
#     for j in range(n):
#         if j == i: continue
#         for k in range(n - 1):
#             p = n - 1 - k
#             if (1 << p) == a[j] / gcd(a[i], a[j]) and (3^k) == a[i] / gcd(a[i], a[j]):
#                 break
#         else:
#             break
#     else:
#         continue
#     start = i
#     break
#

def solve(start, occ, d):
    #print(occ)
    if d == n - 1:
        return True
    u = False
    v = False
    if start / 3 == start // 3 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] -= 1
        u = solve(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] -= 1
        v = solve(start * 2, new_occ, d + 1)

    return u or v

def solve2(start, occ, d):

    if d == n - 1:
        return True, [start]
    u = False, []
    v = False, []
    if start / 3 == start // 3 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] -= 1
        u = solve2(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] -= 1
        v = solve2(start * 2, new_occ, d + 1)

    if u[0]:
        return True, [start] + u[1]
    if v[0]:
        return True, [start] + v[1]

    return False, []

occ = {key: 0 for key in a}

for i in range(n):
    occ[a[i]] += 1

for i in range(n):
    new_occ = dict(occ)
    new_occ[a[i]] -= 1
    if solve(a[i], new_occ, 0):
        new_occ = dict(occ)
        new_occ[a[i]] -= 1
        print(" ".join(str(item) for item in solve2(a[i], new_occ, 0)[1]))
        break


n = int(input())
a = [int(item) for item in input().split()]
#
# def gcd(a, b):
#     while b:
#         a, b = b, a % b
#     return a
#
# start = -1
# for i in range(n):
#     cur = a[i]
#     if cur / 2
#     for j in range(n):
#         if j == i: continue
#         for k in range(n - 1):
#             p = n - 1 - k
#             if (1 << p) == a[j] / gcd(a[i], a[j]) and (3^k) == a[i] / gcd(a[i], a[j]):
#                 break
#         else:
#             break
#     else:
#         continue
#     start = i
#     break
#
ind = {}
for i in range(n):
    ind[a[i]] = i

def solve(start, occ, d):
    if d == n - 1:
        return True
    u = False
    v = False
    if start / 3 == start // 3 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] -= 1
        u = solve(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] -= 1
        v = solve(start * 2, new_occ, d + 1)

    return u or v

def solve2(start, occ, d):

    if d == n - 1:
        return True, [start]
    u = False, []
    v = False, []
    if start / 3 == start // 3 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] -= 1
        u = solve2(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] -= 1
        v = solve2(start * 2, new_occ, d + 1)

    if u[0]:
        return True, [start] + u[1]
    if v[0]:
        return True, [start] + v[1]

    return False, []

occ = {key: 0 for key in a}

for i in range(n):
    occ[a[i]] += 1

for i in range(n):
    new_occ = dict(occ)
    new_occ[a[i]] -= 1
    if solve(a[i], new_occ, 0):
        print(" ".join(str(item) for item in solve2(a[i], occ, 0)[1]))
        break


n = int(input())
a = [int(item) for item in input().split()]
#
# def gcd(a, b):
#     while b:
#         a, b = b, a % b
#     return a
#
# start = -1
# for i in range(n):
#     cur = a[i]
#     if cur / 2
#     for j in range(n):
#         if j == i: continue
#         for k in range(n - 1):
#             p = n - 1 - k
#             if (1 << p) == a[j] / gcd(a[i], a[j]) and (3^k) == a[i] / gcd(a[i], a[j]):
#                 break
#         else:
#             break
#     else:
#         continue
#     start = i
#     break
#
ind = {}
for i in range(n):
    ind[a[i]] = i

def solve(start, occ, d):
    if d == n - 1:
        return True
    u = False
    v = False
    if start / 3 == start // 3 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] -= 1
        u = solve(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] -= 1
        v = solve(start * 2, new_occ, d + 1)

    return u or v

def solve2(start, occ, d):
    #print(occ)
    if d == n - 1:
        return True, [start]
    u = False, []
    v = False, []
    if start / 3 == start // 3 and start // 3 in occ and occ[start // 3] != 0:
        new_occ = dict(occ)
        new_occ[start // 3] -= 1
        u = solve2(start // 3, new_occ, d + 1)

    if start * 2 in occ and occ[start * 2] != 0:
        new_occ = dict(occ)
        new_occ[start * 2] -= 1
        v = solve2(start * 2, new_occ, d + 1)

    if u[0]:
        return True, [start] + u[1]
    if v[0]:
        return True, [start] + v[1]

    return False, []

occ = {key: 0 for key in a}

for i in range(n):
    occ[a[i]] += 1

for i in range(n):
    new_occ = dict(occ)
    new_occ[a[i]] -= 1
    if solve(a[i], new_occ, 0):
        print(" ".join(str(item) for item in solve2(a[i], new_occ, 0)[1]))
        break


n = int(input())
a = [int(x) for x in input().split()]
l = []

for i in range(n):
    if (a[i]/3 not in a) and (a[i]*2 not in a):
        l.append(a.pop(i))
        break

while len(a) != 0:
    if l[0]*3 in a:
        l.insert(0, a.pop(a.index(l[0]*3)))
        continue
    elif l[0]/2 in a:
        l.insert(0, a.pop(a.index(l[0]/2)))
    else:
        l.insert(0, a.pop(0))

for i in l:
    print(i, end=' ')


#include<iostream>
using namespace std;
#include<bits/stdc++.h>

int main()
{
    int n,q;
    cin>>n>>q;

    unordered_map<int,pair<vector<int>,int> > m;
    vector<int> mem;
    int f,x;
    int unread=0;
    while(q-- >0)
    {
        cin>>f>>x;
        if(f==1)
        {
            auto itr=m.find(x);
            if(itr==m.end())
            m.insert({x,{vector<int>{0},0}});
            else
                itr->second.first.push_back(0);

            unread++;
            mem.push_back(x);

        }
        else if(f==2)
        {
            auto itr=m.find(x);
            if(itr!=m.end())
            {
                vector<int> v=itr->second.first;
                for(auto itr=v.begin();itr!=v.end();itr++)
                    {if(*(itr)==0)
                        {
                            *(itr)=1;
                            unread--;

                        }

                    }
            }

        }
        else
        {   int i=0;
            int x_copy=x;
            while(x>0 && i<mem.size())
            {
                int app=mem[i];
                auto itr=m.find(app);
            if(itr!=m.end())
            {
                vector<int> v=itr->second.first;
                if(itr->second.second<v.size() && v[itr->second.second]==0)
                {v[itr->second.second]=1;
                unread--;

                }
                itr->second.second+=1;
            }
            x--;
            i++;

            }
            i=0;
            x=x_copy;
            while(x>0 && i<mem.size())
            {
                int app=mem[i];
                auto itr=m.find(app);
            if(itr!=m.end())
            {
                //vector<int> v=itr->second.first;

                itr->second.second=0;
            }
            x--;
            i++;

            }

        }
        cout<<unread<<endl;

    }

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>

int main()
{

    queue<pair<int,int> > noti;
    unordered_map<int,queue<int> > m;
    int n,q,f,x;
    cin>>n>>q;
    int i=1;
    int unread=0;
    while(q-- >0)
    {
        cin>>f>>x;

        if(f==1)
        {

            noti.push({i,x});
            auto itr=m.find(x);
            if(itr==m.end())
            {queue<int> q;
            q.push(i);
            m.insert({x,q});}
            else
                itr->second.push(i);
            unread++;
            i++;

        }
        else if(f==2)
        {
            auto itr=m.find(x);
            if(itr!=m.end())
            {
                while(!itr->second.empty())
                    {unread--;
                    itr->second.pop();}

            }

        }
        else
        {
            while( !noti.empty() && noti.front().first<=x)
                {
                    pair<int,int> notif=noti.front();
                    noti.pop();

                    auto itr=m.find(notif.second);
                    if(!itr->second.empty() && itr->second.front()==notif.first)
                    {
                        unread--;
                        itr->second.pop();
                    }

                }

        }
        cout<<unread<<endl;

    }

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>

int main()
{
    int n,q;
    cin>>n>>q;

    unordered_map<int,pair<vector<int>,int> > m;
    vector<int> mem;
    int f,x;
    int unread=0;
    while(q-- >0)
    {
        cin>>f>>x;
        if(f==1)
        {
            auto itr=m.find(x);
            if(itr==m.end())
            m.insert({x,{vector<int>{0},0}});
            else
                itr->second.first.push_back(0);

            unread++;
            mem.push_back(x);

        }
        else if(f==2)
        {
            auto itr=m.find(x);
            if(itr!=m.end())
            {
                vector<int> v=itr->second.first;
                for(auto itr=v.begin();itr!=v.end();itr++)
                    {if(*(itr)==0)
                        {*(itr)=1;
                    unread--;}}
            }

        }
        else
        {   int i=0;
            int x_copy=x;
            while(x>0 && i<mem.size())
            {
                int app=mem[i];
                auto itr=m.find(app);
            if(itr!=m.end())
            {
                vector<int> v=itr->second.first;
                if(itr->second.second<v.size() && v[itr->second.second]==0)
                {v[itr->second.second]=1;
                unread--;}
                itr->second.second+=1;
            }
            x--;
            i++;

            }
            i=0;
            x=x_copy;
            while(x>0 && i<mem.size())
            {
                int app=mem[i];
                auto itr=m.find(app);
            if(itr!=m.end())
            {
                //vector<int> v=itr->second.first;

                itr->second.second=0;
            }
            x--;
            i++;

            }

        }
        cout<<unread<<endl;

    }

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>

int main()
{

    queue<pair<int,int> > noti;
    unordered_map<int,queue<int> > m;
    int n,q,f,x;
    cin>>n>>q;
    int i=1;
    int unread=0;
    while(q-- >0)
    {
        cin>>f>>x;

        if(f==1)
        {

            noti.push({i,x});
            auto itr=m.find(x);
            if(itr==m.end())
            {queue<int> q;
            q.push(i);
            m.insert({x,q});}
            else
                itr->second.push(i);
            unread++;
            i++;

        }
        else if(f==2)
        {
            auto itr=m.find(x);
            if(itr!=m.end())
            {
                while(!itr->second.empty())
                    {unread--;
                    itr->second.pop();}

            }

        }
        else
        {
            while(x>0 && !noti.empty())
                {
                    pair<int,int> notif=noti.front();
                    noti.pop();

                    auto itr=m.find(notif.second);
                    if(!itr->second.empty() && itr->second.front()==notif.first)
                    {
                        unread--;
                        itr->second.pop();
                    }

                }

        }
        cout<<unread<<endl;

    }

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>

int main()
{
    int n,q;
    cin>>n>>q;

    unordered_map<int,pair<vector<int>,int> > m;
    vector<int> mem;
    int f,x;
    int unread=0;
    while(q-- >0)
    {
        cin>>f>>x;
        if(f==1)
        {
            auto itr=m.find(x);
            if(itr==m.end())
            m.insert({x,{vector<int>{0},0}});
            else
                itr->second.first.push_back(0);

            unread++;
            mem.push_back(x);

        }
        else if(f==2)
        {
            auto itr=m.find(x);
            if(itr!=m.end())
            {
                vector<int> v=itr->second.first;
                for(auto itr=v.begin();itr!=v.end();itr++)
                    {if(*(itr)==0)
                        {*(itr)=1;
                    if(unread>0)
                    unread--;}}
            }

        }
        else
        {   int i=0;
            int x_copy=x;
            while(x>0 && i<mem.size())
            {
                int app=mem[i];
                auto itr=m.find(app);
            if(itr!=m.end())
            {
                vector<int> v=itr->second.first;
                if(itr->second.second<v.size() && v[itr->second.second]==0)
                {v[itr->second.second]=1;
                if(unread>0)
                unread--;}
                itr->second.second+=1;
            }
            x--;
            i++;

            }
            i=0;
            x=x_copy;
            while(x>0 && i<mem.size())
            {
                int app=mem[i];
                auto itr=m.find(app);
            if(itr!=m.end())
            {
                //vector<int> v=itr->second.first;

                itr->second.second=0;
            }
            x--;
            i++;

            }

        }
        cout<<unread<<endl;

    }

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>
struct node
{
    int t=0;
    int un=0;
    int uns=0;

};

int main()
{
    int n,q;
    cin>>n>>q;

    node ar[n+1];
    vector<int> mem;
    int f,x;
    int unread=0;
    while(q-- > 0)
    {
        cin>>f>>x;
        if(f==1)
        {   if(ar[x].un==0)
                ar[x].uns=ar[x].t+1;

            ar[x].t++;
            ar[x].un++;
            unread++;
            mem.push_back(x);

        }
        else if(f==2)  )
        {
            if(ar[x].un!=0)
            {unread-=ar[x].un;
            ar[x].un=0;
            ar[x].uns++;
            }
        }
        else
        {

            int i=0;
            unordered_map<int,int> m;
            while(x>0 && i<mem.size())
            {
                auto itr=m.find(mem[i]);
                if(itr==m.end())
                m.insert({mem[i],1});
                else
                    itr->second++;
                i++;
                x--;
            }
            for(auto itr=m.begin();itr!=m.end();itr++)
            {
                int no=itr->second;
                int app=itr->first;
                if(ar[app].un>0)
                {
                for(int i=1;i<=no;i++)
                {
                    if(ar[app].uns==i)
                    {   unread--;
                        ar[app].un--;
                        ar[app].uns++;
                    }

                }

                }

            }

        }
        cout<<unread<<endl;

        }

    }


#include<iostream>
using namespace std;
#include<bits/stdc++.h>

int main()
{
    int n,q;
    cin>>n>>q;

    unordered_map<int,pair<vector<int>,int> > m;
    vector<int> mem;
    int f,x;
    int unread=0;
    while(q-- >0)
    {
        cin>>f>>x;
        if(f==1)
        {
            auto itr=m.find(x);
            if(itr==m.end())
            m.insert({x,{vector<int>{0},0}});
            else
                itr->second.first.push_back(0);

            unread++;
            mem.push_back(x);

        }
        else if(f==2)
        {
            auto itr=m.find(x);
            if(itr!=m.end())
            {
                vector<int> v=itr->second.first;
                for(auto it=v.begin();it!=v.end();it++)
                    {if(*(it)==0)
                        {*(it)=1;
                    unread--;}}
            }

        }
        else
        {   int i=0;
            int x_copy=x;
            while(x>0 && i<mem.size())
            {
                int app=mem[i];
                auto itr=m.find(app);
            if(itr!=m.end())
            {
                vector<int> v=itr->second.first;
                if(itr->second.second<v.size() && v[itr->second.second]==0)
                {v[itr->second.second]=1;
                unread--;}
                itr->second.second+=1;
            }
            x--;
            i++;

            }
            i=0;
            x=x_copy;
            while(x>0 && i<mem.size())
            {
                int app=mem[i];
                auto itr=m.find(app);
            if(itr!=m.end())
            {
                //vector<int> v=itr->second.first;

                itr->second.second=0;
            }
            x--;
            i++;

            }

        }
        cout<<unread<<endl;

    }

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>

int main()
{

    queue<pair<int,int> > noti;
    unordered_map<int,queue<int> > m;
    int n,q,f,x;
    cin>>n>>q;
    int i=1;
    int unread=0;
    while(q-- >0)
    {
        cin>>f>>x;

        if(f==1)
        {

            noti.push({i,x});
            auto itr=m.find(x);
            if(itr==m.end())
            {queue<int> q;
            q.push(i);
            m.insert({x,q});}
            else
                itr->second.push(i);
            unread++;

        }
        else if(f==2)
        {
            auto itr=m.find(x);
            if(itr!=m.end())
            {
                while(!itr->second.empty())
                    {unread--;
                    itr->second.pop();}

            }

        }
        else
        {
            while(x>0 && !noti.empty())
                {   x--;
                    pair<int,int> notif=noti.front();
                    noti.pop();

                    auto itr=m.find(notif.second);
                    if(!itr->second.empty() && itr->second.front()==notif.first)
                    {
                        unread--;
                        itr->second.pop();
                    }

                }

        }
        cout<<unread<<endl;

    }

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>

int main()
{

    queue<pair<int,int> > noti;
    unordered_map<int,queue<int> > m;
    int n,q,f,x;
    cin>>n>>q;
    int i=1;
    int unread=0;
    while(q-- >0)
    {
        cin>>f>>x;

        if(f==1)
        {

            noti.push({i,x});
            auto itr=m.find(x);
            if(itr==m.end())
            {queue<int> q;
            q.push(i);
            m.insert({x,q});}
            else
                itr->second.push(i);
            unread++;
            i++;
        }
        else if(f==2)
        {
            auto itr=m.find(x);
            if(itr!=m.end())
            {
                while(!itr->second.empty())
                    {unread--;
                    itr->second.pop();}

            }

        }
        else
        {
            while(x>0 && !noti.empty())
                {
                    x--;
                    pair<int,int> notif=noti.front();
                    noti.pop();

                    auto itr=m.find(notif.second);
                    if(!itr->second.empty() && itr->second.front()==notif.first)
                    {
                        unread--;
                        itr->second.pop();
                    }

                }

        }
        cout<<unread<<endl;

    }

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>

int main()
{
    int n,q;
    cin>>n>>q;

    unordered_map<int,pair<vector<int>,int> > m;
    vector<int> mem;
    int f,x;
    int unread=0;
    while(q-- >0)
    {
        cin>>f>>x;
        if(f==1)
        {
            auto itr=m.find(x);
            if(itr==m.end())
            m.insert({x,{vector<int>{0},0}});
            else
                itr->second.first.push_back(0);

            unread++;
            mem.push_back(x);

        }
        else if(f==2)
        {
            auto itr=m.find(x);
            if(itr!=m.end())
            {

                for(int i=0;i<itr->second.first.size();i++)
                {   //cout<<itr->second.first[i]<<endl;
                    if(itr->second.first[i]==0)
                    {
                        itr->second.first[i]=1;
                        unread--;
                    }
                }

            }

        }
        else
        {   int i=0;
            int x_copy=x;
            while(x>0 && i<mem.size())
            {
                int app=mem[i];
                auto itr=m.find(app);
            if(itr!=m.end())
            {

                if(itr->second.second<itr->second.first.size() && itr->second.first[itr->second.second]==0)
                {itr->second.first[itr->second.second]=1;
                unread--;}
                itr->second.second+=1;
            }
            x--;
            i++;

            }
            i=0;
            x=x_copy;
            while(x>0 && i<mem.size())
            {
                int app=mem[i];
                auto itr=m.find(app);
            if(itr!=m.end())
            {
                //vector<int> v=itr->second.first;

                itr->second.second=0;
            }
            x--;
            i++;

            }

        }
        cout<<unread<<endl;

    }

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>

int main()
{

    queue<pair<int,int> > noti;
    unordered_map<int,queue<int> > m;
    int n,q,f,x;
    cin>>n>>q;
    int i=1;
    int unread=0;
    while(q-- >0)
    {
        cin>>f>>x;

        if(f==1)
        {

            noti.push({i,x});
            auto itr=m.find(x);
            if(itr==m.end())
            {queue<int> q;
            q.push(i);
            m.insert({x,q});}
            else
                itr->second.push(i);
            unread++;

        }
        else if(f==2)
        {
            auto itr=m.find(x);
            if(itr!=m.end())
            {
                while(!itr->second.empty())
                    {unread--;
                    itr->second.pop();}

            }

        }
        else
        {
            while(x>0 && !noti.empty())
                {
                    pair<int,int> notif=noti.front();
                    noti.pop();

                    auto itr=m.find(notif.second);
                    if(!itr->second.empty() && itr->second.front()==notif.first)
                    {
                        unread--;
                        itr->second.pop();
                    }

                }

        }
        cout<<unread<<endl;

    }

}


#include<iostream>
using namespace std;
#include<bits/stdc++.h>
struct node
{
    int t=0;
    int un=0;
    int uns=0;

};

int main()
{
    int n,q;
    cin>>n>>q;

    node ar[n+1];
    vector<int> mem;
    int f,x;
    int unread=0;
    while(q-- > 0)
    {
        cin>>f>>x;
        if(f==1)
        {   if(ar[x].un==0)
                ar[x].uns=ar[x].t+1;

            ar[x].t++;
            ar[x].un++;
            unread++;
            mem.push_back(x);

        }
        else if(f==2)
        {
            if(ar[x].un!=0)
            {unread-=ar[x].un;
            ar[x].un=0;
            ar[x].uns++;}

        }
        else
        {

            int i=0;
            unordered_map<int,int> m;
            while(x>0 && i<mem.size())
            {
                auto itr=m.find(mem[i]);
                if(itr==m.end())
                m.insert({mem[i],1});
                else
                    itr->second++;
                i++;
                x--;
            }
            for(auto itr=m.begin();itr!=m.end();itr++)
            {
                int no=itr->second;
                int app=itr->first;
                if(ar[app].un>0)
                {
                for(int i=1;i<=no;i++)
                {
                    if(ar[app].uns==i)
                    {   unread--;
                        ar[app].un--;
                        ar[app].uns++;
                    }

                }

                }

            }

        }
        cout<<unread<<endl;

        }

    }


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define cases long long test;cin>>test;while(test--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main()
{
    f_io;
    ll n,q;
    cin >> n >> q;
    queue<ll> x;
    map<ll,ll> mp;
    ll ans = 0;
    while(q--)
    {
        ll a,b;
        cin >> a >> b;
        if(a==1)
        {
            x.push(b);
            ans++;
            mp[b]++;
        }
        else if(a==2)
        {
            ans-=mp[b];
            mp[b]=0;
        }
        else
        {
            while(!x.empty() && b--)
            {
                if(mp[x.front()])
                {
                    mp[x.front()]--;
                    ans--;
                }
                x.pop();
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define cases long long test;cin>>test;while(test--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main()
{
    f_io;
    ll n,q;
    cin >> n >> q;
    queue<ll> x;
    map<ll,ll> mp,tot;
    ll ans = 0,c=0;
    while(q--)
    {
        ll a,b;
        cin >> a >> b;
        if(a==1)
        {
            x.push(b);
            ans++;
            mp[b]++;
            tot[b]++;
        }
        else if(a==2)
        {
            ans-=mp[b];
            mp[b]=0;
        }
        else
        {
            b-=c;
            b=max(b,0LL);
            while(!x.empty() && b--)
            {
                if(mp[x.front()] && mp[x.front()]==tot[x.front()])
                {
                    mp[x.front()]--;
                    tot[x.front()]--;
                    ans--;
                }
                x.pop();
                c++;
            }
        }
        cout << ans<< "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define cases long long test;cin>>test;while(test--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main()
{
    f_io;
    ll n,q;
    cin >> n >> q;
    queue<ll> x;
    map<ll,ll> mp;
    ll ans = 0,c=0;
    while(q--)
    {
        ll a,b;
        cin >> a >> b;
        if(a==1)
        {
            x.push(b);
            ans++;
            mp[b]++;
        }
        else if(a==2)
        {
            ans-=mp[b];
            mp[b]=0;
        }
        else
        {
            b-=c;
            b=max(b,0LL);
            while(!x.empty() && b--)
            {
                if(mp[x.front()])
                {
                    mp[x.front()]--;
                    ans--;
                }
                x.pop();
                c++;
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define cases long long test;cin>>test;while(test--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main()
{
    f_io;
    ll n,q;
    cin >> n >> q;
    queue<ll> x;
    map<ll,ll> mp;
    ll ans = 0;
    while(q--)
    {
        ll a,b;
        cin >> a >> b;
        if(a==1)
        {
            x.push(b);
            ans++;
            mp[b]++;
        }
        else if(a==2)
        {
            ans-=mp[b];
            mp[b]=0;
        }
        else
        {
            while(!x.empty() && b)
            {
                if(mp[x.front()])
                {
                    mp[x.front()]--;
                    ans--;
                    b--;
                }
                x.pop();
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define cases long long test;cin>>test;while(test--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main()
{
    f_io;
    ll n,q;
    cin >> n >> q;
    queue<ll> x;
    map<ll,ll> mp;
    ll ans = 0,c=0;
    while(q--)
    {
        ll a,b;
        cin >> a >> b;
        if(a==1)
        {
            x.push(b);
            ans++;
            mp[b]++;
        }
        else if(a==2)
        {
            ans-=mp[b];
            c+=mp[b];
            mp[b]=0;
        }
        else
        {
            b-=c;
            b=max(b,0LL);
            while(!x.empty() && b--)
            {
                if(mp[x.front()])
                {
                    mp[x.front()]--;
                    ans--;
                    c++;
                }
                x.pop();
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define cases long long test;cin>>test;while(test--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main()
{
    f_io;
    ll n,q;
    cin >> n >> q;
    queue<ll> x;
    map<ll,ll> mp,tot;
    ll ans = 0,c=0;
    while(q--)
    {
        ll a,b;
        cin >> a >> b;
        if(a==1)
        {
            x.push(b);
            ans++;
            mp[b]++;
            tot[b]++;
        }
        else if(a==2)
        {
            ans-=mp[b];
            mp[b]=0;
        }
        else
        {
            b-=c;
            b=max(b,0LL);
            while(!x.empty() && b--)
            {
                if(mp[x.front()] && mp[x.front()]==tot[x.front()])
                {
                    mp[x.front()]--;
                    ans--;
                }
                tot[x.front()]--;
                x.pop();
                c++;
            }
        }
        cout << ans<< "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define cases long long test;cin>>test;while(test--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main()
{
    f_io;
    ll n,q;
    cin >> n >> q;
    queue<ll> x;
    map<ll,ll> mp;
    ll ans = 0,c=0;
    while(q--)
    {
        ll a,b;
        cin >> a >> b;
        if(a==1)
        {
            x.push(b);
            ans++;
            mp[b]++;
        }
        else if(a==2)
        {
            ans-=mp[b];
            mp[b]=0;
        }
        else
        {
            b-=c;
            b=max(b,0LL);
            while(!x.empty() && b--)
            {
                if(mp[x.front()])
                {
                    mp[x.front()]--;
                    ans--;
                    c++;
                }
                x.pop();
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,q,t,x,y=0,d[300001],unread[300001],read[300001],ans=0,id=0,k=0;

	cin>>n>>q;

	while(q--){

		cin>>t>>x;

		if(t==1) {unread[x]++;
		ans++;
		d[k++]=x;
		}
		else if(t==2) {read[x]+=unread[x];
		ans-=unread[x];
		unread[x]=0;}

		else
        {   while(id<x)
             {
                y=d[id++];
                if(read[y]) read[y]--;
                else {ans--;unread[y]--;}

            }
        }
		cout<<ans<<endl;

	}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,q,t,x,y,d[300010],unread[300010],read[300010],ans,id,k=0;

	scanf("%d%d",&n,&q);

	while(q--){

		scanf("%d%d",&t,&x);

		if(t==1) {unread[x]++;
		ans++;
		d[k++]=x;
		}
		else if(t==2) {read[x]+=unread[x];
		ans-=unread[x];
		unread[x]=0;}

		else

			{while(id<x){

				y=d[id++];

				if(read[y]) read[y]--;

				else {ans--;unread[y]--;}

			}
			}
		printf("%d\n",ans);

	}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,q,t,x,y=0,d[300010],unread[300010],read[300010],ans=0,id=0,k=0;

	cin>>n>>q;

	while(q--){

		cin>>t>>x;

		if(t==1) {unread[x]++;
		ans++;
		d[k++]=x;
		}
		else if(t==2) {read[x]+=unread[x];
		ans-=unread[x];
		unread[x]=0;}

		else
        {   while(id<x)
             {
                y=d[id++];
                if(read[y]) read[y]--;
                else {ans--;unread[y]--;}

            }
        }
		cout<<ans<<endl;

	}

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int n,q,t,x,y,d[300010],unread[300010],read[300010],ans,id,o;

int main(){

	scanf("%d%d",&n,&q);

	while(q--){

		scanf("%d%d",&t,&x);

		if(t==1) unread[x]++,ans++,d[o++]=x;

		if(t==2) read[x]+=unread[x],ans-=unread[x],unread[x]=0;

		if(t==3)

			while(id<x){

				y=d[id++];

				if(read[y]) read[y]--;

				else ans--,unread[y]--;

			}

		printf("%d\n",ans);

	}

	return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,q,t,x,y=0,d[300010],unread[300010],read[300010],ans=0,id=0,k=0;

	cin>>n>>q;

	while(q--){

		cin>>t>>x;

		if(t==1) {unread[x]++;
		ans++;
		d[k++]=x;
		}
		else if(t==2) {read[x]+=unread[x];
		ans-=unread[x];
		unread[x]=0;}

		else if(t==3)
        {   while(id<x)
             {
                y=d[id++];
                if(read[y]) read[y]--;
                else {ans--;unread[y]--;}

            }
        }
		cout<<ans<<endl;

	}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,q,t,x,y=0,d[300010],unread[300010],read[300010],ans=0,id=0,k=0;
int main()
{

	cin>>n>>q;

	while(q--){

		cin>>t>>x;

		if(t==1) {unread[x]++;
		ans++;
		d[k++]=x;
		}
		else if(t==2) {read[x]+=unread[x];
		ans-=unread[x];
		unread[x]=0;}

		else if(t==3)
        {   while(id<x)
             {
                y=d[id++];
                if(read[y]) read[y]--;
                else {ans--;unread[y]--;}

            }
        }
		cout<<ans<<endl;

	}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
 int n,q,t,x,y=0;

	scanf("%d%d",&n,&q);
 int d[300010],unread[300010],read[300010],ans=0,id=0,k=0;
	while(q--){

		scanf("%d%d",&t,&x);

		if(t==1) {unread[x]++;
		ans++;
		d[k++]=x;
		}
		else if(t==2) {read[x]+=unread[x];
		ans-=unread[x];
		unread[x]=0;}

		else
        {   while(id<x)
             {
                y=d[id++];
                if(read[y]) read[y]--;
                else {ans--;unread[y]--;}

            }
        }
		printf("%d\n",ans);

	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    nt n,q,t,x,y,d[300010],unread[300010],read[300010],ans,id,k=0;

	scanf("%d%d",&n,&q);

	while(q--){

		scanf("%d%d",&t,&x);

		if(t==1) {unread[x]++;
		ans++;
		d[k++]=x;
		}
		else if(t==2) {read[x]+=unread[x];
		ans-=unread[x];
		unread[x]=0;}

		else

			{while(id<x){

				y=d[id++];

				if(read[y]) read[y]--;

				else {ans--;unread[y]--;}

			}
			}
		printf("%d\n",ans);

	}

    return 0;
}


#include<bits/stdc++.h>
#include<string>
#define M_PI 3.14159265358979323846
#define sz(a) (int)(a.size())
//#define pb push_back
#define mk make_pair
#define nl cout<<"\n"
#define sq(a) a*a
#define F first
#define S second

#define pf push_front
#define mod %1000000009
#define EPS 0.0000001
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sd(i) scanf("%d",&i)

#define REP(i, a, b) for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion

// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<string, long long> msl;

/*
double myPow(double x, int n) {
    double res=1;
    if(n<0){
        x=(1/x);
        if(n==INT_MIN){
            res=x;
            n=INT_MAX;
        }
        else
            n*=-1;
    }
    while(n){
        if(n&1){
            res*=x;
            res=res;
        }
        x=((x)*(x));
        n/=2;
    }
    return res;
}

long long pow(long long a, long long b){
    long long res=1;
    while(b){
        if(b&1){
            res*=(a)mod;
            res=(res)mod;
        }
        a=((a)mod*(a)mod)mod;
        b/=2;
    }
    return res;
}

*/

bool compare(pair<int,int > a, pair<int, int > b){
    return false;
}

/*

long long gcd(long long a,long long b){
    long long r;
    while(b){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}

*/

void solution(){
    int n,q,c,t,cnt=0,seq=0;
    queue < pair<int,int> > ql;
    cin>>n>>q;
    vector <int> v(n+1,0);
    while(q--){
        cin>>c>>t;
        if(c==1){
            ql.push(make_pair((++seq),t));
            v[t]++;
            cnt++;
        }
        else if(c==2){
            cnt-=v[t];
            v[t]=0;
        }
        else{
            while(!ql.empty()){
                pair <int,int> p = ql.front();
                //cout<<p.first<<" "<<p.second<<"\n";
                if(p.first>t)
                    continue;
                ql.pop();
                if(v[p.second]>0){
                    v[p.second]--;
                    cnt--;
                }

            }
        }
        cout<<cnt<<"\n";
    }

}

int main(){

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
        solution();
    return 0;
}


#include<bits/stdc++.h>
#include<string>
#define M_PI 3.14159265358979323846
#define sz(a) (int)(a.size())
//#define pb push_back
#define mk make_pair
#define nl cout<<"\n"
#define sq(a) a*a
#define F first
#define S second

#define pf push_front
#define mod %1000000009
#define EPS 0.0000001
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sd(i) scanf("%d",&i)

#define REP(i, a, b) for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion

// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<string, long long> msl;

/*
double myPow(double x, int n) {
    double res=1;
    if(n<0){
        x=(1/x);
        if(n==INT_MIN){
            res=x;
            n=INT_MAX;
        }
        else
            n*=-1;
    }
    while(n){
        if(n&1){
            res*=x;
            res=res;
        }
        x=((x)*(x));
        n/=2;
    }
    return res;
}

long long pow(long long a, long long b){
    long long res=1;
    while(b){
        if(b&1){
            res*=(a)mod;
            res=(res)mod;
        }
        a=((a)mod*(a)mod)mod;
        b/=2;
    }
    return res;
}

*/

bool compare(pair<int,int > a, pair<int, int > b){
    return false;
}

/*

long long gcd(long long a,long long b){
    long long r;
    while(b){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}

*/

void solution(){
    int n,q,c,t,cnt=0,seq=0;
    queue < pair<int,int> > ql;
    cin>>n>>q;
    vector <int> v(n+1,0);
    while(q--){
        cin>>c>>t;
        if(c==1){
            ql.push(make_pair((++seq),t));
            v[t]++;
            cnt++;
        }
        else if(c==2){
            cnt-=v[t];
            v[t]=0;
        }
        else{
            while(!ql.empty()){
                pair <int,int> p = ql.front();
                //cout<<p.first<<" "<<p.second<<"\n";
                if(p.first>t)
                    break;
                ql.pop();
                if(v[p.second]>0){
                    v[p.second]--;
                    cnt--;
                }

            }
        }
        cout<<cnt<<"\n";
    }

}

int main(){

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
        solution();
    return 0;
}


#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,i,urd=0,t,x,c,cnt=0;
    cin>>n>>m;
    queue < pair <int,int> > q;
    vector <int> v(n,0);
    for(i=0;i<m;i++){
        cin>>t;
        if(t==1){
            cin>>c;
            v[c-1]++;
            urd++;
            q.push(make_pair(i+1,c));
            cout<<urd<<"\n";
        }
        else if(t==2){
            cin>>c;
            urd-=v[c-1];
            v[c-1]=0;
            cout<<urd<<"\n";
        }
        else{
            cin>>c;
            while(!q.empty() && cnt<=c){
                if(v[q.front().second-1]>0){
                    urd--;
                    v[q.front().second-1]--;
                }
                cnt++;
                q.pop();
            }
            cout<<urd<<"\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,i,urd=0,t,x,c,temp=1;
    cin>>n>>m;
    queue < pair <int,int> > q;
    vector <int> v(n,0);
    for(i=0;i<m;i++){
        cin>>t;
        if(t==1){
            cin>>c;
            v[c-1]++;
            urd++;
            q.push(make_pair(temp++,c));
            cout<<urd<<"\n";
        }
        else if(t==2){
            cin>>c;
            urd-=v[c-1];
            v[c-1]=0;
            cout<<urd<<"\n";
        }
        else{
            cin>>c;
            while(!q.empty() && q.front().first<=c){
                if(v[q.front().second-1]>0){
                    urd--;
                    v[q.front().second-1]--;
                }
                q.pop();
            }
            cout<<urd<<"\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,i,urd=0,t,x,c,temp=1;
    cin>>n>>m;
    queue < pair <int,int> > q;
    queue <int> qe[n];
    for(i=0;i<m;i++){
        cin>>t;
        if(t==1){
            cin>>c;
            qe[c-1].push(temp);
            urd++;
            q.push(make_pair(temp++,c));
            cout<<urd<<"\n";
        }
        else if(t==2){
            cin>>c;
            urd-=qe[c-1].size();
            queue <int> temp;
            swap(qe[c-1],temp);
            cout<<urd<<"\n";
        }
        else{
            cin>>c;
            while(!q.empty() && q.front().first<=c){
                if(!qe[q.front().second-1].empty() && qe[q.front().second-1].front()<=c){
                    urd--;
                    qe[q.front().second-1].pop();
                }
                q.pop();
            }
            cout<<urd<<"\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,i,urd=0,t,x,c;
    cin>>n>>m;
    queue < pair <int,int> > q;
    vector <int> v(n,0);
    for(i=0;i<m;i++){
        cin>>t;
        if(t==1){
            cin>>c;
            v[c-1]++;
            urd++;
            q.push(make_pair(i+1,c));
            cout<<urd<<"\n";
        }
        else if(t==2){
            cin>>c;
            urd-=v[c-1];
            v[c-1]=0;
            cout<<urd<<"\n";
        }
        else{
            cin>>c;
            while(!q.empty() && q.front().first<=c){
                if(v[q.front().second-1]>0){
                    urd--;
                    v[q.front().second-1]--;
                }
                q.pop();
            }
            cout<<urd<<"\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#include<string>
#define M_PI 3.14159265358979323846
#define sz(a) (int)(a.size())
//#define pb push_back
#define mk make_pair
#define nl cout<<"\n"
#define sq(a) a*a
#define F first
#define S second

#define pf push_front
#define mod %1000000009
#define EPS 0.0000001
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sd(i) scanf("%d",&i)

#define REP(i, a, b) for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion

// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<string, long long> msl;

/*
double myPow(double x, int n) {
    double res=1;
    if(n<0){
        x=(1/x);
        if(n==INT_MIN){
            res=x;
            n=INT_MAX;
        }
        else
            n*=-1;
    }
    while(n){
        if(n&1){
            res*=x;
            res=res;
        }
        x=((x)*(x));
        n/=2;
    }
    return res;
}

long long pow(long long a, long long b){
    long long res=1;
    while(b){
        if(b&1){
            res*=(a)mod;
            res=(res)mod;
        }
        a=((a)mod*(a)mod)mod;
        b/=2;
    }
    return res;
}

*/

bool compare(pair<int,int > a, pair<int, int > b){
    return false;
}

/*

long long gcd(long long a,long long b){
    long long r;
    while(b){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}

*/

void solution(){
    int n,q,c,t,cnt=0,seq=0;
    queue < pair<int,int> > ql;
    vector <int> v(n+1,0);
    cin>>n>>q;
    while(q--){
        cin>>c>>t;
        if(c==1){
            ql.push(make_pair((++seq),t));
            v[t]++;
            cnt++;
        }
        else if(c==2){
            cnt-=v[t];
            v[t]=0;
        }
        else{
            while(!ql.empty()){
                pair <int,int> p = ql.front();
                if(p.first>t)
                    break;
                ql.pop();
                if(v[p.second]>0){
                    v[p.second]--;
                    cnt--;
                }

            }
        }
        cout<<cnt<<"\n";
    }

}

int main(){

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
        solution();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;
        map<int,int>m;
    map <int,int> :: iterator it;
     vector< vector< int > > v(n+1,vector< int >(1));
    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m[y]=b; v[b].push_back(y);}
     else if(a==2)
     {  p=v[b].size();
        for(i=p;i>=0;i--)
        {m.erase(v[b][i]); v[b].resize(i); }

     }

      else
      { for(i=1;i<=b;i++)
        m.erase(i);
      }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include <iostream>
#include<map>
#include <set>
#include <iterator>
#include<bits/stdc++.h>
using namespace std;
int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,b,p;
    cin>>n>>q;
    map<int,int>m;
    map<int,int>::iterator it;
    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m.insert(pair <int, int> (y, b));}
     else if(a==2)
      { for(it=m.begin();it!=m.end();++it)
        { if((it->second)==b) {   m.erase(it); }        }
      }
      else
      {  m.erase(m.begin(), m.find(b+1));  }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;
        map<int,int>m;
    map <int,int> :: iterator it;
     vector< vector< int > > v( n+1, vector< int >( q+1,0 ) );
    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m[y]=b; v[b].push_back(y);}
     else if(a==2)
     {  p=v[b].size();
        for(i=0;i<p;i++)
         m.erase(v[b][i]);

     }

      else
      {  m.erase(m.begin(), m.find(b)); m.erase(b);  }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;

        map<int,int>m;
    map <int,int> :: iterator it;

    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m[y]=b;}
     else if(a==2)
     {  for(it=m.begin();it!=m.end();++it)
     {   if(it->second==b) m.erase(it);

     }
      }
      else
      {  m.erase(m.begin(), m.find(b)); m.erase(b);  }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;
        map<int,int>m;
    map <int,int> :: iterator it;
     vector< vector< int > > v;
    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m[y]=b; v[b].push_back(y);}
     else if(a==2)
     {  p=v[b].size();
        for(i=p;i>=0;i--)
        {m.erase(v[b][i]); v[b][i].pop_back(); }

     }

      else
      { for(i=1;i<=b;i++)
        m.erase(i);
      }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;

        map<int,int>m;
    map <int,int> :: iterator it;

    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m[y]=b;}
     else if(a==2)
     {  for(it=m.begin();it!=m.end();++it)
     {   if(it->second==b) m.erase(it->first);

     }
      }
      else
      {  m.erase(m.begin(), m.find(b)); m.erase(b);  }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<< endl;

using namespace std;

int main()
{
  int i,j,k,n,q,t,a,ans=0,ct=0,mn=99999999,pos=0,flag=1;

  cin>>n>>q;
  std::map<int, int> m;
  std::vector< vector<int> > v(n+1);
  while(q--)
  {
    cin>>t>>a;
    if(t==1)
    {
      ct++; m[ct]=a; v[a].push_back(ct);
    }
    else if(t==2)
    {
      for(i=v[a].size()-1;i>=0;i--)
      {
        m.erase(v[a][i]);
      }
      v[a].resize(0);
    }
    else
    {
      auto it =m.lower_bound(a);
      it++;
      m.erase(m.begin(),it);
    }

    cout<<m.size()<<"\n";

  }

}


#include<bits/stdc++.h>
using namespace std;

int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;
        map<int,int>m;
    map <int,int> :: iterator it;
     vector< vector< int > > v(n+1,vector< int >(1,0));
    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m[y]=b; v[b].push_back(y);}
     else if(a==2)
     {  p=v[b].size();
        for(i=p-1;i>=0;i--)
        {m.erase(v[b][i]); v[b].resize(i); }

     }

      else
      { for(i=1;i<=b;i++)
        m.erase(i);
      }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,b,p;
    cin>>n>>q;

        map<int,int>m;

    for(x=0;x<q;x++)
    { cin>>a>>b;

      if(a==1)
      { y++; m.insert(pair <int, int> (y, b));}
     else if(a==2)
      { map<int,int>::iterator it;
         for(it=m.begin();it!=m.end();++it)
        { if((it->second)==b) {   m.erase(it); }        }
      }
      else
      {  m.erase(m.begin(), m.find(b+1));  }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;
        map<int,int>m;
    map <int,int> :: iterator it;
     vector< vector< int > > v(n+1,vector< int >(1,0));
    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m[y]=b; v[b].push_back(y);}
     else if(a==2)
     {  p=v[b].size();
        for(i=p-1;i>=0;i--)
        {m.erase(v[b][i]); v[b].resize(i); }

     }

      else
      {
         if(m.begin()!=m.lower_bound(b))
         { m.erase(m.begin(),m.lower_bound(b));m.erase(b);}
          else m.erase(b);
      }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<< endl;

using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int i,j,k,n,q,t,a,ans=0,ct=0,mn=99999999,pos=0,flag=1;

  cin>>n>>q;
  std::map<int, int> m;
  std::vector< vector<int> > v(n+1);
  while(q--)
  {
    cin>>t>>a;
    if(t==1)
    {
      ct++; m[ct]=a; v[a].push_back(ct);
    }
    else if(t==2)
    {
      for(i=v[a].size()-1;i>=0;i--)
      {
        m.erase(v[a][i]);
      }
      v[a].resize(0);
    }
    else
    {
      auto it =m.lower_bound(a);
      it++;
      m.erase(m.begin(),it);
    }

    cout<<m.size()<<"\n";

  }

}


#include<map>
#include <iostream>
#include <set>
#include <iterator>
using namespace std;
int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,b,p;
    cin>>n>>q;
    map<int,int>m;
    map<int,int>::iterator it;
    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m.insert(pair <int, int> (y, b));}
     else if(a==2)
      { for(it=m.begin();it!=m.end();it++)
        { if((it->second)==b) m.erase(it);

        }
      }
      else
      {  m.erase(m.begin(), m.find(b+1));  }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;
        map<int,int>m;
    map <int,int> :: iterator it;
     vector< vector< int > > v(n+1,vector< int >(1,0));
    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m[y]=b; v[b].push_back(y);}
     else if(a==2)
     {  p=v[b].size();
        for(i=p-1;i>=0;i--)
        {m.erase(v[b][i]); v[b].resize(i); }

     }

      else
      {
         if(m.begin()!=m.lower_bound(b))
          m.erase(m.begin(),m.lower_bound(b));
          else m.erase(b);
      }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<map>
#include <iostream>
#include <set>
#include <iterator>
using namespace std;
int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,b;
    cin>>n>>q;
    map<int,int>m;
    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m.insert(pair <int, int> (y, b));}
      else if(a==2)
      { m.erase(b);}
      else
      {  m.erase(m.begin(), m.find(b+1));  }
     cout<<m.size()<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;
        map<int,int>m;
    map <int,int> :: iterator it;
     vector< vector< int > > v(n+1,vector< int >(1,0));
    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m[y]=b; v[b].push_back(y);}
     else if(a==2)
     {  p=v[b].size();
        for(i=p;i>=0;i--)
        {m.erase(v[b][i]); v[b].resize(i); }

     }

      else
      { for(i=1;i<=b;i++)
        m.erase(i);
      }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<map>
#include <iostream>
#include <set>
#include <iterator>
using namespace std;
int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,b,p;
    cin>>n>>q;
    map<int,int>m;
    map<int,int>::iterator it=m.begin();
    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m.insert(pair <int, int> (y, b));}
     else if(a==2)
      { for(it=m.begin();it!=m.end();it++)
        { if((it->second)==b) m.erase(it);

        }
      }
      else
      {  m.erase(m.begin(), m.find(b+1));  }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,b,p;
    cin>>n>>q;
    map<int,int>m;

    for(x=0;x<q;x++)
    { cin>>a>>b;
       map<int,int>::iterator it;
      if(a==1)
      { y++; m.insert(pair <int, int> (y, b));}
     else if(a==2)
      { for(it=m.begin();it!=m.end();++it)
        { if((it->second)==b) {   m.erase(it); }        }
      }
      else
      {  m.erase(m.begin(), m.find(b+1));  }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,b,p;
    cin>>n>>q;

    for(x=0;x<q;x++)
    { cin>>a>>b;
    map<int,int>m;
     map<int,int>::iterator it;
      if(a==1)
      { y++; m.insert(pair <int, int> (y, b));}
     else if(a==2)
      { for(it=m.begin();it!=m.end();++it)
        { if((it->second)==b) {   m.erase(it); }        }
      }
      else
      {  m.erase(m.begin(), m.find(b+1));  }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>

#include <iostream>
using namespace std;
#include <set>
#include<map>
#include <iterator>

int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;

        map<long int,long int>m;

    for(x=0;x<q;x++)
    { cin>>a>>b;
       map <long int,long int> :: iterator it=m.begin();
      if(a==1)
      { y++; m[y]=b;}
     else if(a==2)
     {
         for(i=1;i<=y;i++)
         if(m[i]==b) { m.erase(i);}
      }
      else
      {  m.erase(m.begin(), m.find(b+1));  }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<map>
#include <iostream>
#include <set>
#include <iterator>
using namespace std;
int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;

        map<int,int>m;
   map<int,int>::iterator it;

    for(x=0;x<q;x++)
    { cin>>a>>b;

      if(a==1)
      { y++; m.insert(pair <int, int> (y, b));}
     else if(a==2)
     {   it=m.end();
         it--;
         for(i=1;i<(it->first);i++)
         if(m[i]==b) { m.erase(i);}
      }
      else
      {  m.erase(m.begin(), m.find(b+1));  }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include <bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<< endl;

using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int i,j,k,n,q,t,a,ans=0,ct=0,mn=99999999,pos=0,flag=1;

  cin>>n>>q;
  std::map<int, int> m;
  auto it = m.end();
  std::vector< vector<int> > v(n+1);
  while(q--)
  {
    cin>>t>>a;
    if(t==1)
    {
      ct++; m[ct]=a; v[a].push_back(ct);
    }
    else if(t==2)
    {
      for(i=v[a].size()-1;i>=0;i--)
      {
        m.erase(v[a][i]);
      }
      v[a].resize(0);
    }
    else
    {
      it =m.lower_bound(a);
      if(it->first==a)
      it++;
      m.erase(m.begin(),it);
    }

    cout<<m.size()<<"\n";

  }

}


#include<bits/stdc++.h>

#include <iostream>
using namespace std;
#include <set>
#include<map>
#include <iterator>

int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;

        map<int,int>m;
    map <int,int> :: iterator it;

    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m[y]=b;}
     else if(a==2)
     {  for(it=m.begin();it!=m.end();++it)
     {   if((*it).second==b) m.erase(it);

     }
      }
      else
      {  m.erase(m.begin(), m.find(b)); m.erase(b);  }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{  cin.tie(NULL);
    int n,x,y=0,q,a,i,b,p;
    cin>>n>>q;
        map<int,int>m;
    map <int,int> :: iterator it;
     vector< vector< int > > v( n+1, vector< int >( q+1,0 ) );
    for(x=0;x<q;x++)
    { cin>>a>>b;
      if(a==1)
      { y++; m[y]=b; v[b].push_back(y);}
     else if(a==2)
     {  p=v[b].size();
        for(i=0;i<p;i++)
         m.erase(v[b][i]);

     }

      else
      { for(i=1;i<=b;i++)
        m.erase(i);
      }
     cout<<m.size()<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define mp make_pair
using namespace std;

void solve(){
	int n,q;
	cin>>n>>q;
	vector <int> v[n];
	int a[n]={0};
	ll cnt = 0;
	int x,y,idx=0;
	for (int i = 0; i < q; ++i)
	{
		cin>>x>>y;
		if (x==1)
		{
			v[y-1].push_back(idx);
			cnt++;
		}
		else if (x==2)
		{
			for (int i = 0; i < v[y-1].size(); ++i)
			{
				if (a[v[y-1][i]]==0)
				{
					a[v[y-1][i]]=1;
					cnt--;
				}
			}
		}
		else{
			for (int i = 0; i < y; ++i)
			{
				if (a[i]==0)
				{
					a[i]=1;
					cnt--;
				}
			}
		}
		cout<<cnt<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define mp make_pair
using namespace std;

void solve(){
	int n,q;
	cin>>n>>q;
	vector <int> v[n];
	int a[q]={0};
	ll cnt = 0;
	int x,y,idx=0;
	for (int i = 0; i < q; ++i)
	{
		cin>>x>>y;
		if (x==1)
		{
			v[y-1].push_back(idx);
			cnt++;
			idx++;
		}
		else if (x==2)
		{
			for (int i = 0; i < v[y-1].size(); ++i)
			{
				if (a[v[y-1][i]]==0)
				{
					a[v[y-1][i]]=1;
					cnt--;
				}
			}
		}
		else{
			for (int i = 0; i < y; ++i)
			{
				if (a[i]==0)
				{
					a[i]=1;
					cnt--;
				}
			}
		}
		cout<<cnt<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define mp make_pair
using namespace std;

void solve(){
	int n,q;
	cin>>n>>q;
	vector <int> v[n];
	int a[q]={0};
	ll cnt = 0;
	int x,y,idx=0;
	for (int i = 0; i < q; ++i)
	{
		cin>>x>>y;
		if (x==1)
		{
			v[y-1].push_back(idx);
			cnt++;
		}
		else if (x==2)
		{
			for (int i = 0; i < v[y-1].size(); ++i)
			{
				if (a[v[y-1][i]]==0)
				{
					a[v[y-1][i]]=1;
					cnt--;
				}
			}
		}
		else{
			for (int i = 0; i < y; ++i)
			{
				if (a[i]==0)
				{
					a[i]=1;
					cnt--;
				}
			}
		}
		cout<<cnt<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define mp make_pair
using namespace std;

void solve(){
	int n,q,t=0;
	cin>>n>>q;
	vector <int> v[n];
	int a[q]={0};
	ll cnt = 0;
	int x,y,idx=0;
	for (int i = 0; i < q; ++i)
	{
		cin>>x>>y;
		if (x==1)
		{
			v[y-1].push_back(idx);
			cnt++;
			idx++;
		}
		else if (x==2)
		{
			for (int i = 0; i < v[y-1].size(); ++i)
			{
				if (a[v[y-1][i]]==0)
				{
					a[v[y-1][i]]=1;
					cnt--;
				}
			}
			v[y-1].clear();
		}
		else{
			for (int i = 0; i < y-t; ++i)
			{
				if (a[i]==0)
				{
					a[i]=1;
					cnt--;
				}
			}
			t = max(y,t);
		}
		cout<<cnt<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define mp make_pair
using namespace std;

void solve(){
	int n,q;
	cin>>n>>q;
	vector <int> v[n];
	int a[n]={0};
	ll cnt = 0;
	int x,y,idx=0;
	for (int i = 0; i < q; ++i)
	{
		cin>>x>>y;
		if (x==1)
		{
			v[y-1].push_back(idx);
			cnt++;
		}
		else if (x==2)
		{
			for (int i = 0; i < v[y].size(); ++i)
			{
				if (a[v[y][i]]==0)
				{
					a[v[y][i]]=1;
					cnt--;
				}
			}
		}
		else{
			for (int i = 0; i < y; ++i)
			{
				if (a[i]==0)
				{
					a[i]=1;
					cnt--;
				}
			}
		}
		cout<<cnt<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define mp make_pair
using namespace std;

void solve(){
	int n,q,t=0;
	cin>>n>>q;
	vector <int> v[n];
	int a[q]={0};
	ll cnt = 0;
	int x,y,idx=0;
	for (int i = 0; i < q; ++i)
	{
		cin>>x>>y;
		if (x==1)
		{
			v[y-1].push_back(idx);
			cnt++;
			idx++;
		}
		else if (x==2)
		{
			for (int i = 0; i < v[y-1].size(); ++i)
			{
				if (a[v[y-1][i]]==0)
				{
					a[v[y-1][i]]=1;
					cnt--;
				}
			}
			v[y-1].clear();
		}
		else{
			for (int i = t; i < y; ++i)
			{
				if (a[i]==0)
				{
					a[i]=1;
					cnt--;
				}
			}
			t = max(y,t);
		}
		cout<<cnt<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define mp make_pair
using namespace std;

void solve(){
	int n,q;
	cin>>n>>q;
	vector <int> v[n];
	int a[q]={0};
	ll cnt = 0;
	int x,y,idx=0;
	for (int i = 0; i < q; ++i)
	{
		cin>>x>>y;
		if (x==1)
		{
			v[y-1].push_back(idx);
			cnt++;
			idx++;
		}
		else if (x==2)
		{
			for (int i = 0; i < v[y-1].size(); ++i)
			{
				if (a[v[y-1][i]]==0)
				{
					a[v[y-1][i]]=1;
					cnt--;
				}
			}
			v[y-1].erase();
		}
		else{
			for (int i = 0; i < y; ++i)
			{
				if (a[i]==0)
				{
					a[i]=1;
					cnt--;
				}
			}
		}
		cout<<cnt<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define mp make_pair
using namespace std;

void solve(){
	int n,q;
	cin>>n>>q;
	vector <pair <int, int>> v;
	ll cnt = 0;
	int x,y;
	for (int i = 0; i < q; ++i)
	{
		cin>>x>>y;
		if (x==1)
		{
			v.push_back(make_pair(y,0));
			cnt++;
		}
		else if (x==2)
		{
			for (int i = 0; i < v.size(); ++i)
			{
				if (v[i].first==y && v[i].second==0)
				{
					v[i].second=1;
					cnt--;
				}
			}
		}
		else{
			for (int i = 0; i < y; ++i)
			{
				if (v[i].second==0)
				{
					v[i].second=1;
					cnt--;
				}
			}
		}
		cout<<cnt<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define mp make_pair
using namespace std;

void solve(){
	int n,q;
	cin>>n>>q;
	vector <int> v[n];
	int a[q]={0};
	ll cnt = 0;
	int x,y,idx=0;
	for (int i = 0; i < q; ++i)
	{
		cin>>x>>y;
		if (x==1)
		{
			v[y-1].push_back(idx);
			cnt++;
			idx++;
		}
		else if (x==2)
		{
			for (int i = 0; i < v[y-1].size(); ++i)
			{
				if (a[v[y-1][i]]==0)
				{
					a[v[y-1][i]]=1;
					cnt--;
				}
			}
			v[y-1].clear();
		}
		else{
			for (int i = 0; i < y; ++i)
			{
				if (a[i]==0)
				{
					a[i]=1;
					cnt--;
				}
			}
		}
		cout<<cnt<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int n,k,l,s,sum,c=0;
cin>>n>>k;
vector<pair <int,int> >v;
map<int,int> m;
vector<pair <int,int> >::iterator it;
map<int,int>::iterator itr;
for(int i=0;i<n;i++)
{
    m[i+1]=0;
}
for(int i=0;i<k;i++)
{sum=0;
    cin>>l>>s;
    v.push_back(pair<int,int> (l,s));
    if(l==1)
        m[s]++;
    if(l==2)
        m[s]=0;
    if(l==3)
    {
        for(it=v.begin();it!=v.end();it++)
        {
            if(it->first==1)
                {c++;
                    if(c<s)
                       m[it->second]=0;
                }
        }

    }
    for(itr=m.begin();itr!=m.end();itr++)
        {
            sum=sum+ itr->second;
        }
    cout<<sum<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int n,k,l,s,sum;
cin>>n>>k;
vector<pair <int,int> >v;
map<int,int> m;
vector<pair <int,int> >::iterator it;
map<int,int>::iterator itr;
for(int i=0;i<n;i++)
{
    m[i+1]=0;
}
for(int i=0;i<k;i++)
{sum=0;
    cin>>l>>s;
    v.push_back(pair<int,int> (l,s));
    if(l==1)
        m[s]++;
    if(l==2)
        m[s]=0;
    if(l==3)
    {
        for(it=v.begin();it!=v.end();it++)
        {
            if(it->first==1)
                {
                    m[it->second]=0;
                }
        }

    }
    for(itr=m.begin();itr!=m.end();itr++)
        {
            sum=sum+ itr->second;
        }
    cout<<sum<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int n,k,l,s,sum,c=0;
cin>>n>>k;
vector<pair <int,int> >v;
map<int,int> m;
vector<pair <int,int> >::iterator it;
map<int,int>::iterator itr;
for(int i=0;i<n;i++)
{
    m[i+1]=0;
}
for(int i=0;i<k;i++)
{sum=0;
    cin>>l>>s;
    v.push_back(pair<int,int> (l,s));
    if(l==1)
        m[s]++;
    if(l==2)
        m[s]=0;
    if(l==3)
    {c=0;
        for(it=v.begin();it!=v.end();it++)
        {
            if(it->first==1)
                {c++;
                    if(c<=s)
                       m[it->second]=0;
                }
        }

    }
    for(itr=m.begin();itr!=m.end();itr++)
        {
            sum=sum+ itr->second;
        }
    cout<<sum<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int n,k,l,s,sum,c=0;
cin>>n>>k;
vector<pair <int,int> >v;
map<int,int> m;
vector<pair <int,int> >::iterator it;
map<int,int>::iterator itr;
for(int i=0;i<n;i++)
{
    m[i+1]=0;
}
for(int i=0;i<k;i++)
{sum=0;
    cin>>l>>s;
    v.push_back(pair<int,int> (l,s));
    if(l==1)
        m[s]++;
    if(l==2)
        m[s]=0;
    if(l==3)
    {c=0;
        for(it=v.begin();it!=v.end();it++)
        {
            if(it->first==1)
                {c++;
                    if(c<s&&(m[it->second]==0||m[it->second]!=0))
                       m[it->second]=0;
                }
        }

    }
    for(itr=m.begin();itr!=m.end();itr++)
        {
            sum=sum+ itr->second;
        }
    cout<<sum<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long n,qr,a,b,ans=0,p,s,i,g=1;
    queue<pair<long,long> >q;
    map<long,queue<long> >m;
    cin>>n>>qr;
    bool visit[qr+1];
    fill(visit,visit+qr+1,0);
    for(i=1;i<=qr;i++)
    {
        cin>>a>>b;
        if(a==1)
        {
            m[b].push(g);
            q.push({g,b});
            ans++;
            g++;
        }
        else if(a==2)
        {
            while(!m[b].empty())
            {
                visit[m[b].front()]=1;
                m[b].pop();
                ans--;
            }
        }
        else
        {
            while(!q.empty()&&q.front().first<=b)
            {
                p=q.front().first;
                s=q.front().second;
                q.pop();
                if(!visit[p])
                {
                    visit[p]=1;
                    m[s].pop();
                    ans--;
                }
            }
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int n,k,l,s,sum;
cin>>n>>k;
vector<pair <int,int> >v;
map<int,int> m;
vector<pair <int,int> >::iterator it;
map<int,int>::iterator itr;
for(int i=0;i<n;i++)
{
    m[i+1]=0;
}
for(int i=0;i<k;i++)
{sum=0;
    cin>>l>>s;
    v.push_back(pair<int,int> (l,s));
    if(l==1)
        m[s]++;
    if(l==2)
        m[s]=0;
    if(l==3)
    {
        for(it=v.begin();it!=v.end();it++)
        {
            if(it->first==3)
                m[it->second]=0;
        }

    }
    for(itr=m.begin();itr!=m.end();itr++)
        {
            sum=sum+ itr->second;
        }
    cout<<sum<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int n,k,l,s,sum,c=0;
cin>>n>>k;
vector<pair <int,int> >v;
map<int,int> m;
vector<pair <int,int> >::iterator it;
map<int,int>::iterator itr;
for(int i=0;i<n;i++)
{
    m[i+1]=0;
}
for(int i=0;i<k;i++)
{sum=0;
    cin>>l>>s;
    v.push_back(pair<int,int> (l,s));
    if(l==1)
        m[s]++;
    if(l==2)
        m[s]=0;
    if(l==3)
    {c=0;
        for(it=v.begin();it!=v.end();it++)
        {
            if(it->first==1)
                {c++;
                    if(c<s)
                       m[it->second]=0;
                }
        }

    }
    for(itr=m.begin();itr!=m.end();itr++)
        {
            sum=sum+ itr->second;
        }
    cout<<sum<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int n,k,l,s,sum,c=0;
cin>>n>>k;
vector<pair <int,int> >v;
map<int,int> m;
vector<pair <int,int> >::iterator it;
map<int,int>::iterator itr;
for(int i=0;i<n;i++)
{
    m[i+1]=0;
}
for(int i=0;i<k;i++)
{sum=0;
    cin>>l>>s;
    v.push_back(pair<int,int> (l,s));
    if(l==1)
        m[s]++;
    if(l==2)
        m[s]=0;
    if(l==3)
    {c=0;
        for(it=v.begin();it!=v.begin()+s;it++)
        {m[it->second]=0;
        }

    }
    for(itr=m.begin();itr!=m.end();itr++)
        {
            sum=sum+ itr->second;
        }
    cout<<sum<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,q,j,k,sum=0;
    map<int,int> m;
    map<int,int>::iterator it;
    cin>>n>>q;
    for(int j=0;j<n;j++)
    {
        m[j+1]=0;
    }
    for(int i=0;i<q;i++)
    {sum=0;
        cin>>j>>k;
        if(j==1)
          m[k]++;
        if(j==2)
        m[k]=0;
        if(j==3)
        {
            for(it=m.begin();it!=m.end();it++)
                {it->second=0;
                sum=0;
        }
        }
        for(it=m.begin();it!=m.end();it++)
        {
            sum=sum+ it->second;
        }
        cout<<sum<<endl;

    }
return 0;
}


#include<bits/stdc++.h>
#define rep1(i,n,a) for(int i=0;i<n;i+=a)
#define rep2(i,n,a) for(int i=a;i<n;i++)
#define rep3(n)     for(int i=0;i<n;i++)
#define inarr(arr,n) rep1(i,n,1)cin>>arr[i]
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define trav(a,x) for(auto x:a)
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define gcd(a,b) __gcd(a,b)
#define pres(a,x) a.find(x)!=a.end()
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define psi pair<string,int>
#define pss pair<string,string>
#define pll pair<ll,ll>
#define vec vector<int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define hell 1000000007
#define narak 998244353
const int inf1=1e9;
const ll inf2=1e18;
using namespace std;
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
// syntax for min priority_queue of pairs
// priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
int solve(){
  int n,q;cin>>n>>q;
  int arr[q+1]={0};
  int dp=1;
  int s=0;
  queue<int> v[n+1];
  queue<int> qu;
  int no=1;
  int mp[q+1];
  for(int i=1;i<=q;i++){
      int t=1;
      cin>>t;
      if(t==1){
        s++;
        int x;cin>>x;
        v[x].push(no);
        mp[no]=x;
        qu.push(no);
        no++;
      }
      if(t==2){
          int x;cin>>x;
          while(!v[x].empty()){
              int k=v[x].front();
              arr[k]=1;
              v[x].pop();
              s--;
          }
      }
      if(t==3){
          int x;cin>>x;
          while(!qu.empty()){
           int ve=qu.front();
           if(ve>x)break;
           if(arr[ve]==0){
               arr[ve]=1;
               s--;
               v[mp[ve]].pop();
           }
           qu.pop();
          }
      }
      cout<<s<<endl;
      /**cout<<"--------------"<<endl;
      for(int j=1;j<=n;j++){
          if(v[j].size()==0)continue;cout<<j<<" ";
          for(auto k:v[j])cout<<k<<" ";cout<<endl;
      }
      cout<<"--------------"<<endl;**/
      //for(int j=1;j<=i;j++)cout<<arr[j]<<" ";cout<<endl;

  }
  ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}


//https://codeforces.com/contest/704/problem/A
#include<bits/stdc++.h>
#define lop(i,n,a) for(int i=0;i<n;i+=a)
#define rep(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define pii pair<int,int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
int solve(){
  int n,q;cin>>n>>q;
  int un=0;
  map<int,int> mp;
  vector<vector<int>> v;
  v.resize(n);
  int visit[q]={0};
  //lop(i,q,1)visit[i]=1;
  int t=0;
  lop(i,q,1){
      int a,x;
      cin>>a>>x;
      if(a==1){
          un++;
          mp[x]++;
          v[x-1].pb(i);
          visit[i]=1;
      }
      else if(a==2){
          un-=mp[x];
          mp[x]=0;
          for(auto i:v[x-1])visit[i]=0;
          v[x-1].clear();
      }
      else{
          for(int i=0;i<x;i++){
            if(visit[i]==1){visit[i]=0,un--;}
          }
      }
      cout<<un<<endl;
  }

}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ll t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}


#include<bits/stdc++.h>
#define rep1(i,n,a) for(int i=0;i<n;i+=a)
#define rep2(i,n,a) for(int i=a;i<n;i++)
#define rep3(n)     for(int i=0;i<n;i++)
#define inarr(arr,n) rep1(i,n,1)cin>>arr[i]
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define trav(a,x) for(auto x:a)
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define gcd(a,b) __gcd(a,b)
#define pres(a,x) a.find(x)!=a.end()
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define psi pair<string,int>
#define pss pair<string,string>
#define pll pair<ll,ll>
#define vec vector<int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define hell 1000000007
#define narak 998244353
const int inf1=1e9;
const ll inf2=1e18;
using namespace std;
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
// syntax for min priority_queue of pairs
// priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
int solve(){
  int n,q;cin>>n>>q;
  int arr[q+1]={0};
  int dp=1;
  int s=0;
  vector<int> v[n+1];
  int no=1;
  for(int i=1;i<=q;i++){
      int t=1;
      cin>>t;
      if(t==1){
        s++;
        int x;cin>>x;
        v[x].pb(no);
        no++;
      }
      if(t==2){
          int x;cin>>x;
          for(auto j:v[x]){
              if(arr[j]==0){
                  arr[j]=1;
                  s--;
              }
          }
          v[x].clear();
      }
      if(t==3){
          int x;cin>>x;
          for(int j=dp;j<=x;j++){
              if(arr[j]==0){
                  arr[j]=1;
                  s--;
              }
          }
          dp=x+1;
      }
      cout<<s<<endl;
      /**cout<<"--------------"<<endl;
      for(int j=1;j<=n;j++){
          if(v[j].size()==0)continue;cout<<j<<" ";
          for(auto k:v[j])cout<<k<<" ";cout<<endl;
      }
      cout<<"--------------"<<endl;**/
      //for(int j=1;j<=i;j++)cout<<arr[j]<<" ";cout<<endl;

  }
  ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}


#include<bits/stdc++.h>
#define rep1(i,n,a) for(int i=0;i<n;i+=a)
#define rep2(i,n,a) for(int i=a;i<n;i++)
#define rep3(n)     for(int i=0;i<n;i++)
#define inarr(arr,n) rep1(i,n,1)cin>>arr[i]
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define trav(a,x) for(auto x:a)
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define gcd(a,b) __gcd(a,b)
#define pres(a,x) a.find(x)!=a.end()
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define psi pair<string,int>
#define pss pair<string,string>
#define pll pair<ll,ll>
#define vec vector<int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define hell 1000000007
#define narak 998244353
const int inf1=1e9;
const ll inf2=1e18;
using namespace std;
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
// syntax for min priority_queue of pairs
// priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
int solve(){
  int n,q;cin>>n>>q;
  int arr[q+1]={0};
  int dp=1;
  int s=0;
  queue<int> v[n+1];
  queue<int> qu;
  int no=1;
  int mp[q+1];
  for(int i=1;i<=q;i++){
      int t=1;
      cin>>t;
      if(t==1){
        s++;
        int x;cin>>x;
        v[x].push(no);
        mp[no]=x;
        qu.push(no);
        no++;
      }
      if(t==2){
          int x;cin>>x;
          while(!v[x].empty()){
              int k=v[x].front();
              arr[k]=1;
              v[x].pop();
              s--;
          }
      }
      if(t==3){
          int x;cin>>x;
          while(!qu.empty()){
           int ve=qu.front();
           if(ve>x)break;
           if(arr[ve]==0){
               arr[ve]=1;
               s--;
           }
           qu.pop();
          }
      }
      cout<<s<<endl;
      /**cout<<"--------------"<<endl;
      for(int j=1;j<=n;j++){
          if(v[j].size()==0)continue;cout<<j<<" ";
          for(auto k:v[j])cout<<k<<" ";cout<<endl;
      }
      cout<<"--------------"<<endl;**/
      //for(int j=1;j<=i;j++)cout<<arr[j]<<" ";cout<<endl;

  }
  ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}


//https://codeforces.com/contest/704/problem/A
#include<bits/stdc++.h>
#define lop(i,n,a) for(int i=0;i<n;i+=a)
#define rep(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define pii pair<int,int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
int solve(){
  int n,q;cin>>n>>q;
  int un=0;
  map<int,int> mp;
  vector<vector<int>> v;
  v.resize(n);
  int visit[q]={0};
  int t=0;
  lop(i,q,1){
      int a,x;
      cin>>a>>x;
      if(a==1){
          un++;
          mp[x]++;
          v[x-1].pb(i);
      }
      else if(a==2){
          un-=mp[x];
          mp[x]=0;
          for(auto i:v[x-1])visit[i]=1;
      }
      else{
          for(int i=0;i<x;i++){
            if(visit[i]==0){visit[i]=1,un--;}
          }
      }
      cout<<un<<endl;
  }

}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ll t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}


//https://codeforces.com/contest/704/problem/A
#include<bits/stdc++.h>
#define lop(i,n,a) for(int i=0;i<n;i+=a)
#define rep(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define pii pair<int,int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
int solve(){
  int n,q;cin>>n>>q;
  int un=0;
  map<int,int> mp;
  vector<int> v;
  int t=0;
  lop(i,q,1){
      int a,x;
      cin>>a>>x;
      if(a==1){
          un++;
          mp[x]++;
          v.pb(x);
      }
      else if(a==2){
          un-=mp[x];
          mp[x]=0;
      }
      else{
          if(x>t){
          for(int i=t;i<x;i++){
              mp[v[i]]--;
              un--;
          }
          t=x;
        }
      }
      cout<<un<<endl;
  }

}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ll t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}


#include<bits/stdc++.h>
#define rep1(i,n,a) for(int i=0;i<n;i+=a)
#define rep2(i,n,a) for(int i=a;i<n;i++)
#define rep3(n)     for(int i=0;i<n;i++)
#define inarr(arr,n) rep1(i,n,1)cin>>arr[i]
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define trav(a,x) for(auto x:a)
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define gcd(a,b) __gcd(a,b)
#define pres(a,x) a.find(x)!=a.end()
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define psi pair<string,int>
#define pss pair<string,string>
#define pll pair<ll,ll>
#define vec vector<int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define hell 1000000007
#define narak 998244353
const int inf1=1e9;
const ll inf2=1e18;
using namespace std;
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
// syntax for min priority_queue of pairs
// priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
int solve(){
  int n,q;cin>>n>>q;
  int arr[q+1]={0};
  int dp=1;
  int s=0;
  vector<int> v[n+1];
  for(int i=1;i<=q;i++){
      int t=1;
      cin>>t;
      if(t==1){
        s++;
        int x;cin>>x;
        v[x].pb(i);
      }
      if(t==2){
          int x;cin>>x;
          for(auto j:v[x]){
              if(arr[j]==0){
                  arr[j]=1;
                  s--;
              }
          }
          v[x].clear();
      }
      if(t==3){
          int x;cin>>x;
          for(int j=dp;j<=x;j++){
              if(arr[j]==0){
                  arr[j]=1;
                  s--;
              }
          }
          dp=x+1;
      }
      cout<<s<<endl;
  }
  ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}