#include #include #include #include #include using namespace std; int main() { int n, m; cin >> n >> m; vector> ab(n); for (int i = 0; i < n; ++i) cin >> ab[i].first; for (int i = 0; i < n; ++i) cin >> ab[i].second; vector t0, t1; for (int i = 0; i < m; ++i) { int t, c; cin >> t >> c; if (t == 0) { t0.push_back(c); } else { t1.push_back(c); } } sort(t0.begin(), t0.end()); sort(t1.begin(), t1.end()); priority_queue, vector>, greater<>> small; priority_queue large; for (int i = 0; i < n; ++i) { small.emplace(ab[i]); } for (const auto x : t0) { while (small.size() && small.top().first <= x) { auto [a, b] = small.top(); small.pop(); large.emplace(min(a, b)); } if (large.empty()) { continue; } large.pop(); } vector min_v; while (small.size()) { auto [a, b] = small.top(); small.pop(); min_v.push_back(min(a, b)); } while (large.size()) { min_v.push_back(large.top()); large.pop(); } sort(min_v.rbegin(), min_v.rend()); for (const auto x : t1) { if (min_v.empty()) { break; } if (min_v.back() <= x) { min_v.pop_back(); } } cout << min_v.size() << endl; return 0; }