Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).

q events are about to happen (in chronological order). They are of three types:  Application x generates a notification (this new notification is unread).  Thor reads all notifications generated so far by application x (he may re-read some notifications).  Thor reads the first t notifications generated by phone applications (notifications generated in first t events of the first type). It's guaranteed that there were at least t events of the first type before this event. Please note that he doesn't read first t unread notifications, he just reads the very first t notifications generated on his phone and he may re-read some of them in this operation. 

Please help Thor and tell him the number of unread notifications after each event. You may assume that initially there are no notifications in the phone.


-----Input-----

The first line of input contains two integers n and q (1 ≤ n, q ≤ 300 000) — the number of applications and the number of events to happen.

The next q lines contain the events. The i-th of these lines starts with an integer type_{i} — type of the i-th event. If type_{i} = 1 or type_{i} = 2 then it is followed by an integer x_{i}. Otherwise it is followed by an integer t_{i} (1 ≤ type_{i} ≤ 3, 1 ≤ x_{i} ≤ n, 1 ≤ t_{i} ≤ q).


-----Output-----

Print the number of unread notifications after each event.


-----Examples-----
Input
3 4
1 3
1 1
1 2
2 3

Output
1
2
3
2

Input
4 6
1 2
1 4
1 2
3 3
1 3
1 3

Output
1
2
3
0
1
2



-----Note-----

In the first sample:  Application 3 generates a notification (there is 1 unread notification).  Application 1 generates a notification (there are 2 unread notifications).  Application 2 generates a notification (there are 3 unread notifications).  Thor reads the notification generated by application 3, there are 2 unread notifications left. 

In the second sample test:  Application 2 generates a notification (there is 1 unread notification).  Application 4 generates a notification (there are 2 unread notifications).  Application 2 generates a notification (there are 3 unread notifications).  Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left.  Application 3 generates a notification (there is 1 unread notification).  Application 3 generates a notification (there are 2 unread notifications).

Difficulty: MEDIUM_HARD

Solutions:
import collections
import sys
(n, q) = map(int, sys.stdin.readline().split(' '))
notifApp = collections.defaultdict(collections.deque)
notifs = collections.deque()
sol = []
total = 0
m = 0
ctd = 0
for i in range(q):
	(tipo, x) = map(int, sys.stdin.readline().split(' '))
	if tipo == 1:
		notifApp[x].append(ctd)
		notifs.append(x)
		total += 1
		ctd += 1
	elif tipo == 2:
		actual = notifApp[x]
		if len(actual) > 0:
			total -= len(actual)
			del notifApp[x]
	else:
		while x > m:
			primero = notifs.popleft()
			actual = notifApp[primero]
			if len(actual) > 0 and actual[0] < x:
				actual.popleft()
				total -= 1
				if len(actual) == 0:
					del notifApp[primero]
			m += 1
	sol.append(total)
sys.stdout.write('\n'.join(map(str, sol)))


import sys, collections
(n, q) = map(int, input().split())
M = collections.defaultdict(collections.deque)
Q = collections.deque()
L = []
s = n = m = 0
for _ in range(q):
	(y, x) = map(int, input().split())
	if 2 > y:
		s += 1
		Q.append(x)
		M[x].append(n)
		n += 1
	elif 3 > y:
		y = M.get(x)
		if y:
			s -= len(y)
			del M[x]
	else:
		while x > m:
			z = Q.popleft()
			y = M.get(z)
			if y and y[0] < x:
				s -= 1
				y.popleft()
				if not y:
					del M[z]
			m += 1
	L.append(s)
sys.stdout.write('\n'.join(map(str, L)))


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	(N, Q) = getInts()
	order = []
	cur_total = 0
	cur_del = -1
	els = [0] * (N + 1)
	del_up_to = [-1] * (N + 1)
	for q in range(Q):
		(T, X) = getInts()
		if T == 1:
			order.append(X)
			els[X] += 1
			cur_total += 1
			print(cur_total)
		elif T == 2:
			cur_total -= els[X]
			els[X] = 0
			del_up_to[X] = max(len(order) - 1, del_up_to[X])
			print(cur_total)
		elif T == 3:
			if X - 1 > cur_del:
				for i in range(cur_del + 1, X):
					if del_up_to[order[i]] < i:
						cur_total -= 1
						del_up_to[order[i]] = i
						els[order[i]] -= 1
				cur_del = X - 1
			print(cur_total)
	return
solve()


(n, q) = map(int, input().split())
l = []
a = [[] for _ in range(n)]
tp = 0
ans = 0
anss = []
for i in range(q):
	(x, b) = map(int, input().split())
	if x == 1:
		l.append(1)
		a[b - 1].append(len(l) - 1)
		ans += 1
	elif x == 2:
		while len(a[b - 1]) > 0:
			z = a[b - 1].pop()
			ans -= l[z]
			l[z] = 0
	else:
		while tp < b:
			ans -= l[tp]
			l[tp] = 0
			tp += 1
	anss.append(str(ans))
print('\n'.join(anss))


import collections
import sys
(n, q) = map(int, input().split())
hash = {}
deque = collections.deque()
messageNumber = 1
unread = 0
L = []
for i in range(q):
	(c, x) = map(int, input().split())
	if c == 1:
		if x not in hash:
			hash[x] = set()
		hash[x].add(messageNumber)
		deque.append((x, messageNumber))
		messageNumber += 1
		unread += 1
	elif c == 2:
		if x in hash:
			xUnread = len(hash[x])
			hash[x] = set()
			unread -= xUnread
	else:
		t = x
		read = 0
		while len(deque) != 0 and deque[0][1] <= t:
			(app, message) = deque.popleft()
			if message in hash[app]:
				read += 1
				hash[app].remove(message)
		unread -= read
	L.append(unread)
print('\n'.join(map(str, L)))


import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, q) = map(int, input().split())
last_2 = [-1] * n
unread_count = [0] * n
total_unread = 0
ev = []
max_3 = 0
ans = []
for i in range(q):
	(t, x) = map(int, input().split())
	x -= 1
	if t == 1:
		ev.append(x)
		unread_count[x] += 1
		total_unread += 1
	elif t == 2:
		total_unread -= unread_count[x]
		unread_count[x] = 0
		last_2[x] = len(ev) - 1
	else:
		for j in range(max_3, x + 1):
			el = ev[j]
			if last_2[el] < j:
				total_unread -= 1
				unread_count[el] -= 1
		max_3 = max(max_3, x + 1)
	ans.append(total_unread)
for a in ans:
	print(a)


from heapq import *
from collections import defaultdict, deque
total = 0
(N, Q) = map(int, input().split())
q = deque()
idx = 0
total = 0
A = [0] * N
B = [0] * N
ans = []
for _ in range(Q):
	(t, x) = map(int, input().split())
	x -= 1
	if t == 1:
		q.append(x)
		A[x] += 1
		B[x] += 1
		total += 1
	elif t == 2:
		total -= A[x]
		A[x] = 0
	else:
		while idx <= x:
			idx += 1
			y = q.popleft()
			B[y] -= 1
			if B[y] < A[y]:
				total -= 1
				A[y] = B[y]
	ans.append(str(total))
print('\n'.join(ans))


from collections import deque as dq
(a, b) = map(int, input().split())
arr = dq()
p = [0] * a
q = list(p)
tot = 0
no = 0
l = dq()
for i in range(0, b):
	(x, y) = map(int, input().split())
	if x == 1:
		arr.append(y - 1)
		p[y - 1] = p[y - 1] + 1
		q[y - 1] = q[y - 1] + 1
		tot = tot + 1
		l.append(tot)
	elif x == 2:
		tot = tot - p[y - 1]
		p[y - 1] = 0
		l.append(tot)
	else:
		while y > no:
			w = arr[0]
			arr.popleft()
			q[w] = q[w] - 1
			if p[w] > q[w]:
				p[w] = p[w] - 1
				tot = tot - 1
			no = no + 1
		l.append(tot)
for i in l:
	print(i)


from sys import stdout
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
print = stdout.write
(n, q) = map(int, input().split())
d = [[] for i in range(n + 1)]
mark = []
ans = 0
inde = 0
t = 0
for i in range(q):
	(event, x) = map(int, input().split())
	if event == 1:
		ans += 1
		d[x].append(inde)
		inde += 1
		mark.append(False)
	elif event == 2:
		for j in d[x]:
			if not mark[j]:
				mark[j] = True
				ans -= 1
		d[x] = []
	else:
		for j in range(t, x):
			if not mark[j]:
				mark[j] = True
				ans -= 1
		if x > t:
			t = x
	print(str(ans) + '\n')


import collections
(n, q) = map(int, input().split())
dq = collections.deque()
l = n * [0]
p = list(l)
ans = 0
t = 0
ansl = []
while q:
	(a, b) = map(int, input().split())
	if a == 1:
		dq.append(b - 1)
		(l[b - 1], p[b - 1]) = (l[b - 1] + 1, p[b - 1] + 1)
		ans = ans + 1
	elif a == 2:
		ans = ans - l[b - 1]
		l[b - 1] = 0
	else:
		while b > t:
			t = t + 1
			j = dq.popleft()
			p[j] = p[j] - 1
			if l[j] > p[j]:
				l[j] = l[j] - 1
				ans = ans - 1
	ansl.append(str(ans))
	q = q - 1
print('\n'.join(ansl))


(n, q) = map(int, input().split())
stacks = [[] for i in range(n + 1)]
queue = []
q_start = 0
unread = 0
ans = []
for i in range(q):
	(action, num) = map(int, input().split())
	if action == 1:
		queue.append(0)
		stacks[num].append(len(queue) - 1)
		unread += 1
	elif action == 2:
		for i in range(len(stacks[num])):
			if stacks[num][i] >= q_start and queue[stacks[num][i]] == 0:
				queue[stacks[num][i]] = 1
				unread -= 1
		stacks[num] = []
	else:
		for i in range(q_start, num):
			if queue[i] == 0:
				queue[i] = 1
				unread -= 1
		q_start = max(q_start, num)
	ans.append(unread)
print('\n'.join(map(str, ans)))


(n, q) = list(map(int, input().split()))
count = [0 for i in range(n + 1)]
queue = []
read = set()
unread = 0
ans = []
last_q_idx = 0
last_app_idx = [1 for i in range(n + 1)]
for i in range(q):
	(action, num) = list(map(int, input().split()))
	if action == 1:
		queue.append((num, count[num] + 1))
		count[num] += 1
		unread += 1
	elif action == 2:
		for number in range(last_app_idx[num], count[num] + 1):
			if (num, number) not in read:
				read.add((num, number))
				unread -= 1
		last_app_idx[num] = max(last_app_idx[num], count[num])
	else:
		for idx in range(last_q_idx, num):
			(app, number) = queue[idx]
			if (app, number) not in read:
				read.add((app, number))
				last_app_idx[app] = max(last_app_idx[app], number)
				unread -= 1
		last_q_idx = max(last_q_idx, num)
	ans.append(unread)
print('\n'.join(map(str, ans)))


from sys import stdin
input = stdin.readline
(n, q) = map(int, input().split())
is_read_index = 0
is_read = []
l = [[] for i in range(n)]
ans = 0
prev = 0
for _ in range(q):
	(t, v) = map(int, input().split())
	if t == 1:
		l[v - 1].append(is_read_index)
		is_read_index += 1
		is_read.append(False)
		ans += 1
	elif t == 2:
		for idx in l[v - 1]:
			if not is_read[idx]:
				is_read[idx] = True
				ans -= 1
		l[v - 1] = []
	elif v > prev:
		for idx in range(prev, v):
			if not is_read[idx]:
				is_read[idx] = True
				ans -= 1
		prev = v
	print(ans)