#include using namespace std; using ll = long long; int solve(vector> a, vector a1, vector b){ int n = a.size(); int ans = 0; sort(a.rbegin(), a.rend()); set S; S.insert(1 << 30); priority_queue pq; for(int i = 0; i < a1.size(); i++) pq.emplace(a1[i]); for(auto &&v : b) S.insert(v); for(int i = 0; i < n; i++){ int v, v2; tie(v, v2) = a[i]; if(!pq.empty() && pq.top() >= v){ pq.pop(); continue; } auto it = S.lower_bound(v2); if(*it == (1 << 30)) ans++; else S.erase(it); } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m, t, v; cin >> n >> m; vector> a(n); vector a1, a2; for(int i = 0; i < n; i++) cin >> a[i].first; for(int i = 0; i < n; i++) cin >> a[i].second; for(int i = 0; i < m; i++){ cin >> t >> v; if(t == 0) a1.emplace_back(v); else a2.emplace_back(v); } int ans = solve(a, a1, a2); for(int i = 0; i < n; i++) swap(a[i].first, a[i].second); ans = min(ans, solve(a, a2, a1)); cout << ans << '\n'; }