import bisect def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) M = int(data[idx+1]) idx +=2 A = list(map(int, data[idx:idx+N])) idx +=N B = list(map(int, data[idx:idx+N])) idx +=N t0 = [] t1 = [] for _ in range(M): T = int(data[idx]) C = int(data[idx+1]) idx +=2 if T == 0: t0.append(C) else: t1.append(C) # Sort the buyers' lists t0.sort() t1.sort() # Prepare products with their min_p, preferred type, a, b products = [] for i in range(N): a = A[i] b = B[i] min_p = min(a, b) preferred = 0 if a <= b else 1 products.append( (min_p, preferred, a, b) ) # Sort products by min_p products.sort(key=lambda x: x[0]) ptr0 = 0 ptr1 = 0 count = 0 for p in products: min_p, preferred, a, b = p if preferred == 0: # Try T0 first idx0 = bisect.bisect_left(t0, a, ptr0) if idx0 < len(t0): count +=1 ptr0 = idx0 +1 else: # Try T1's B price idx1 = bisect.bisect_left(t1, b, ptr1) if idx1 < len(t1): count +=1 ptr1 = idx1 +1 else: # Try T1 first idx1 = bisect.bisect_left(t1, b, ptr1) if idx1 < len(t1): count +=1 ptr1 = idx1 +1 else: # Try T0's A price idx0 = bisect.bisect_left(t0, a, ptr0) if idx0 < len(t0): count +=1 ptr0 = idx0 +1 print(N - count) if __name__ == "__main__": main()