import heapq n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a2 = [[a[i], i] for i in range(n)] b2 = [[b[i], i] for i in range(n)] a2.sort() b2.sort() ls = [list(map(int, input().split())) for _ in range(n)] ls.sort(key = lambda x: x[1]) flg = [0] * n h1 = [] h2 = [] idxa = 0 idxb = 0 for t, c in ls: while idxa < n: if a2[idxa][0] > c: break heapq.heappush(h1, (-a2[idxa][0])*n+a2[idxa][1]) idxa += 1 while idxb < n: if b2[idxb][0] > c: break heapq.heappush(h2, (-b2[idxb][0])*n+b2[idxb][1]) idxb += 1 if t: while h2: tmp = heapq.heappop(h2) x, i = divmod(tmp, n) x *= -1 if flg[i] == 0: flg[i] = 1 break else: while h1: tmp = heapq.heappop(h1) x, i = divmod(tmp, n) x *= -1 if flg[i] == 0: flg[i] = 1 break # print(flg, t, c) # print(h1, h2) print(n - sum(flg)) # print(flg)