import heapq n,m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.append(10**10) b.append(10**10) n+=1 aa = [] bb = [] for i in range(n): aa.append((a[i], i)) bb.append((b[i], i)) aa.sort() bb.sort() ok = [1 for _ in range(n)] tt = [] for _ in range(m): t,c = map(int, input().split()) tt.append((c, t)) tt.sort() anow = 0 ha = [] bnow = 0 hb = [] for c,t in tt: #print(c,t) if(t==1): while(1): if(aa[anow][0] > c): break heapq.heappush(ha, (-b[aa[anow][1]], aa[anow][1])) anow+=1 while(ha): _, i = heapq.heappop(ha) if(ok[i]==1): ok[i]=0 #print(i) break else: while(1): if(bb[bnow][0] > c): break heapq.heappush(hb, (-a[bb[bnow][1]], bb[bnow][1])) bnow+=1 while(hb): _, i = heapq.heappop(hb) if(ok[i]==1): ok[i]=0 #print(i) break print(sum(ok)-1)