#include using namespace std; const int INF = 10000000; template struct lazy_segment_tree{ int N; vector ST; vector lazy; lazy_segment_tree(vector &A){ int n = A.size(); N = 1; while (N < n){ N *= 2; } ST = vector(N * 2 - 1, -INF); lazy = vector(N * 2 - 1, 0); for (int i = 0; i < n; i++){ ST[N - 1 + i] = A[i]; } for (int i = N - 2; i >= 0; i--){ ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]); } } void eval(int i){ if (i < N - 1){ lazy[i * 2 + 1] += lazy[i]; lazy[i * 2 + 2] += lazy[i]; } ST[i] += lazy[i]; lazy[i] = 0; } void range_add(int L, int R, T x, int i, int l, int r){ eval(i); if (R <= l || r <= L){ return; } else if (L <= l && r <= R){ lazy[i] += x; eval(i); } else { int m = (l + r) / 2; range_add(L, R, x, i * 2 + 1, l, m); range_add(L, R, x, i * 2 + 2, m, r); ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]); } } void range_add(int L, int R, T x){ range_add(L, R, x, 0, 0, N); } T all(){ eval(0); return ST[0]; } }; int main(){ int N, M; cin >> N >> M; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } vector B(N); for (int i = 0; i < N; i++){ cin >> B[i]; } vector T(M), C(M); for (int i = 0; i < M; i++){ cin >> T[i] >> C[i]; } vector> C2(2); for (int i = 0; i < M; i++){ C2[T[i]].push_back(C[i]); } for (int i = 0; i < 2; i++){ sort(C2[i].begin(), C2[i].end()); } int H = C2[0].size() + 1; int W = C2[1].size() + 1; vector x(N), y(N); for (int i = 0; i < N; i++){ x[i] = C2[0].end() - lower_bound(C2[0].begin(), C2[0].end(), A[i]); y[i] = C2[1].end() - lower_bound(C2[1].begin(), C2[1].end(), B[i]); } vector> add(H); for (int i = 0; i < N; i++){ add[x[i]].push_back(y[i]); } vector a(W); for (int i = 0; i < W; i++){ a[i] = -i; } lazy_segment_tree ST(a); int ans = 0; for (int i = 0; i < H; i++){ for (int j : add[i]){ ST.range_add(j, W, 1); } ans = max(ans, ST.all()); ST.range_add(0, W, -1); } cout << ans << endl; }