#include using namespace std; using ll = long long; using P = pair; using T = tuple; // #include // using namespace atcoder; // using mint = modint1000000007; #define rep(i, n) for(ll i = 0; i < n; i++) int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); ll n,m; cin >> n >> m; priority_queue,greater

> a, b, mem; rep(i,n) { ll aa; cin >> aa; a.push(P(aa,i)); } rep(i,n) { ll bb; cin >> bb; b.push(P(bb,i)); } rep(i,m) { ll t,c; cin >> t >> c; mem.push(P(c,t)); } ll ans = 0; set bought; while( !mem.empty() ) { auto [money,t] = mem.top(); mem.pop(); if( t == 0 ) { while( !a.empty() && bought.count(a.top().second) ) a.pop(); if( !a.empty() && a.top().first <= money ) { bought.insert(a.top().second); ans++; a.pop(); } } else { while( !b.empty() && bought.count(b.top().second) ) b.pop(); if( !b.empty() && b.top().first <= money ) { bought.insert(b.top().second); ans++; b.pop(); } } } cout << n-ans << endl; return 0; }