#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int n, m; cin >> n >> m; vector a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; multiset> general, mma; rep(i, n) { general.insert({ a[i], b[i] }); mma.insert({ b[i], a[i] }); } vector> q(m); rep(i, m) cin >> q[i].first >> q[i].second; sort(q.begin(), q.end(), [](auto a, auto b) { return a.second < b.second; }); rep(i, m) { auto [t, c] = q[i]; auto&& my = (t == 0 ? general : mma); auto&& opp = (t == 0 ? mma : general); auto itr = my.upper_bound({ c, 2e9 }); if (itr == my.begin()) continue; auto [a, b] = *prev(itr); auto itr1 = my.find({ a, b }); my.erase(itr1); auto itr2 = opp.find({ b, a }); opp.erase(itr2); } assert(general.size() == mma.size()); cout << general.size() << endl; return 0; }