#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int n,m; cin>>n>>m; vector> a(n);//,b(n); rep(i,n)cin>>a[i].first; rep(i,n)cin>>a[i].second; sort(a.begin(),a.end()); vector> t(2); rep(i,m){ int x,y; cin>>x>>y; t[x].push_back(y); } rep(i,2)sort(t[i].begin(),t[i].end()); int ans = 0; priority_queue Q; int cp = 0; rep(i,t[0].size()){ while(cp!=n && a[cp].first <= t[0][i]){ Q.push(a[cp].second); cp++; } if(Q.size()>0){ ans++; Q.pop(); } } for(int i=cp;i b; while(Q.size()>0){ b.insert(Q.top()); Q.pop(); } rep(i,t[1].size()){ if(b.size()==0)break; auto it = b.upper_bound(t[1][i]); if(it==b.begin())continue; it--; ans++; b.erase(it); } cout<