#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int N, A, B; vi aa, bb; void solve(){ int ans = 0; multisetsa, sb; while(N--){ if(!sz(sa))sa.insert(all(aa)); if(!sz(sb))sb.insert(all(bb)); auto minit = sb.begin(), maxit = --sb.end(); auto it = sa.lower_bound(*minit + 1); if(it != sa.end()){ ans++; auto itb = --sb.lower_bound(*it); sa.erase(it); sb.erase(minit); } else{ sa.erase(sa.begin()); sb.erase(maxit); } } cout << ans << endl; } int main(){ while(cin >> N){ cin >> A; aa.resize(A); rep(i, A)scanf("%d", &aa[i]); cin >> B; bb.resize(B); rep(i, B)scanf("%d", &bb[i]); solve(); } }