""" とりあえず、小さい方から見る すると、自分が買わなかったものは後の人が買えるので、どれを選んでもOK 後は、相手側の一番高い物を買えばよい…? """ import sys from sys import stdin import heapq N,M = map(int,stdin.readline().split()) A = list(map(int,stdin.readline().split())) B = list(map(int,stdin.readline().split())) CT = [] for i in range(M): T,C = map(int,stdin.readline().split()) CT.append( (C,T) ) CT.sort() able = [True] * N AtoB = [(A[i],B[i],i) for i in range(N)] AtoB.sort(); AtoB.reverse() BtoA = [(B[i],A[i],i) for i in range(N)] BtoA.sort(); BtoA.reverse() q0 = [] q1 = [] ans = N for C,T in CT: if T == 0: while AtoB and AtoB[-1][0] <= C: na,nb,i = AtoB.pop() heapq.heappush( q0 , (-nb,i) ) while q0: mnb,i = heapq.heappop(q0) if able[i]: able[i] = False ans -= 1 break else: while BtoA and BtoA[-1][0] <= C: nb,na,i = BtoA.pop() heapq.heappush( q1, (-na,i) ) while q1: mna,i = heapq.heappop(q1) if able[i]: able[i] = False ans -= 1 break print (ans)