from collections import deque n, k, q_ = map(int, input().split()) dq = deque(maxlen=n) for i in range(q_): q = int(input()) if q == 1: dq.append(input()) else: L = [input().split() for i in range(6)] tm, t = 60, [] for a, b in L: b = int(b) if a in dq: b = min(b, k) tm -= b if tm < 0: break t.append(a) for tt in t: dq.append(tt) print(len(t))