import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ## n,k,q = na() z = [] for _ in range(q): q = ni() if q == 1: s = input() z.append(s) if len(z) > n: z.pop(0) else: t,d = zip(*[input().split() for i in range(6)]) d = [int(i) for i in d] s = 0 ans = 0 for i in range(6): if t[i] in z: s += min(k, d[i]) else: s += d[i] if s <= 60: ans = i + 1 for i in range(ans): z.append(t[i]) if len(z) > n: z.pop(0) print(ans)