#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 1e18
using namespace std;
struct edge{
	long long to, flow, cap, rev;
};
vector<edge>e[20005];
int club[20005], cek[20005]={}, str[20005];
int source, sink, tengah;
int n, m, q;
int st[20005], lvl[20005];
void addedge(long long x, long long y, long long cap){
	edge a = {y, 0, cap, (long long)e[y].size()};
	edge b = {x, 0, 0, (long long)e[x].size()};
	e[x].pb(a);
	e[y].pb(b);
}
long long bfs(){
	for(long long i = 0; i <= sink; i++)lvl[i] = 0;
	lvl[source] = 1;
	queue<long long>q;
	q.push(source);
	while(!q.empty()){
		long long x = q.front();
		q.pop();
		for(long long i =0 ; i < e[x].size(); i++){
			edge ee = e[x][i];
			if(ee.flow < ee.cap && lvl[ee.to] == 0){
				q.push(ee.to);
				lvl[ee.to] = lvl[x]+1;
			}
		}
	}
	return lvl[sink];
}
long long dfs(long long x, long long f){
	if(x == sink)return f;
	for(; st[x] < e[x].size(); st[x]++){
		edge ee = e[x][st[x]];
		if(lvl[ee.to] != lvl[x]+1 || ee.flow == ee.cap)continue;
		long long flow = dfs(ee.to, min(ee.cap - ee.flow, f));
		if(flow){
			e[x][st[x]].flow += flow;
			e[ee.to][ee.rev].flow -= flow;
			return flow;
		}
	}
	return 0;
}
int maxflow(int las){
	int cnt = las+1;
	for(int i = 0; i <= sink; i++)e[i].clear();

	for(int i = 1; i <= m; i++)addedge(source, i, 1);

	for(int i = 0; i < n; i++)
		if(str[i] <= las){
			addedge(club[i], tengah + str[i], 1);
			if(cek[i] == 0){
				cnt++;
				addedge(source, club[i], 1);
				addedge(tengah + str[i], sink, 1);
			}
		}

	for(int i = 0; i <= las; i++){
		addedge(tengah + i, sink, 1);
	}
	int total = 0;
	while(bfs()){
		for(int i = 0; i <= sink; i++)st[i] = 0;
		while(int flow = dfs(0, 9999999))
			total += flow;
	}
	return (total==cnt);
}
int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++)cin >> str[i];
	for(int i = 0; i < n; i++)cin >> club[i];
	for(int i = 0; i < n; i++)cek[i] = 1;
	cin >> q;
	source = 0;
	tengah = m + 1;
	sink = tengah + 5000 + 1;
	int las = -1;
	for(int i = 0; i <= tengah+1; i++){
		int temp = maxflow(i);
		if(temp == 0)break;
		las = i;
	}
	int cnt = 0;
	while(q--){
		int x;
		scanf("%d",&x);
		cek[x-1] = 0;
		cnt++;
		while(las >= 0 && maxflow(las) == 0){
			las--;
		}
		int mex = las+1;
		printf("%d\n",mex);
	}
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 1e18
using namespace std;
struct edge{
	long long to, flow, cap, rev;
};
vector<edge>e[10005];
int club[10005], cek[10005]={}, str[10005];
int source, sink, tengah;
int n, m, q;
int st[10005], lvl[10005];
void addedge(long long x, long long y, long long cap){
	edge a = {y, 0, cap, (long long)e[y].size()};
	edge b = {x, 0, 0, (long long)e[x].size()};
	e[x].pb(a);
	e[y].pb(b);
}
long long bfs(){
	for(long long i = 0; i <= sink; i++)lvl[i] = 0;
	lvl[source] = 1;
	queue<long long>q;
	q.push(source);
	while(!q.empty()){
		long long x = q.front();
		q.pop();
		for(long long i =0 ; i < e[x].size(); i++){
			edge ee = e[x][i];
			if(ee.flow < ee.cap && lvl[ee.to] == 0){
				q.push(ee.to);
				lvl[ee.to] = lvl[x]+1;
			}
		}
	}
	return lvl[sink];
}
long long dfs(long long x, long long f){
	if(x == sink)return f;
	for(; st[x] < e[x].size(); st[x]++){
		edge ee = e[x][st[x]];
		if(lvl[ee.to] != lvl[x]+1 || ee.flow == ee.cap)continue;
		long long flow = dfs(ee.to, min(ee.cap - ee.flow, f));
		if(flow){
			e[x][st[x]].flow += flow;
			e[ee.to][ee.rev].flow -= flow;
			return flow;
		}
	}
	return 0;
}
int maxflow(int las){
	int cnt = las+1;
	for(int i = 0; i <= sink; i++)e[i].clear();

	for(int i = 1; i <= m; i++)addedge(source, i, 1);

	for(int i = 0; i < n; i++)
		if(str[i] <= las){
			addedge(club[i], tengah + str[i], 1);
			if(cek[i] == 0){
				cnt++;
				addedge(source, club[i], 1);
				addedge(tengah + str[i], sink, 1);
			}
		}

	for(int i = 0; i <= las; i++){
		addedge(tengah + i, sink, 1);
	}
	int total = 0;
	while(bfs()){
		for(int i = 0; i <= sink; i++)st[i] = 0;
		while(int flow = dfs(0, 9999999))
			total += flow;
	}
	return (total==cnt);
}
int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++)cin >> str[i];
	for(int i = 0; i < n; i++)cin >> club[i];
	for(int i = 0; i < n; i++)cek[i] = 1;
	cin >> q;
	source = 0;
	tengah = m + 1;
	sink = tengah + 5000 + 1;
	int las = -1;
	for(int i = 0; i <= tengah+1; i++){
		int temp = maxflow(i);
		if(temp == 0)break;
		las = i;
	}
	int cnt = 0;
	while(q--){
		int x;
		cin >> x;
		cek[x-1] = 0;
		cnt++;
		while(las >= 0 && maxflow(las) == 0){
			las--;
		}
		int mex = las+1;
		cout << mex << endl;
	}
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 1e18
using namespace std;
struct edge{
	long long to, flow, cap, rev;
};
vector<edge>e[20005];
int club[20005], cek[20005]={}, str[20005];
int source, sink, tengah;
int n, m, q;
int st[20005], lvl[20005];
void addedge(long long x, long long y, long long cap){
	edge a = {y, 0, cap, (long long)e[y].size()};
	edge b = {x, 0, 0, (long long)e[x].size()};
	e[x].pb(a);
	e[y].pb(b);
}
long long bfs(){
	for(long long i = 0; i <= sink; i++)lvl[i] = 0;
	lvl[source] = 1;
	queue<long long>q;
	q.push(source);
	while(!q.empty()){
		long long x = q.front();
		q.pop();
		for(long long i =0 ; i < e[x].size(); i++){
			edge ee = e[x][i];
			if(ee.flow < ee.cap && lvl[ee.to] == 0){
				q.push(ee.to);
				lvl[ee.to] = lvl[x]+1;
			}
		}
	}
	return lvl[sink];
}
long long dfs(long long x, long long f){
	if(x == sink)return f;
	for(; st[x] < e[x].size(); st[x]++){
		edge ee = e[x][st[x]];
		if(lvl[ee.to] != lvl[x]+1 || ee.flow == ee.cap)continue;
		long long flow = dfs(ee.to, min(ee.cap - ee.flow, f));
		if(flow){
			e[x][st[x]].flow += flow;
			e[ee.to][ee.rev].flow -= flow;
			return flow;
		}
	}
	return 0;
}
int maxflow(int las){
	int cnt = las+1;
	for(int i = 0; i <= sink; i++)e[i].clear();

	for(int i = 1; i <= m; i++)addedge(source, i, 1);

	for(int i = 0; i < n; i++)
		if(str[i] <= las){
			addedge(club[i], tengah + str[i], 1);
			if(cek[i] == 0){
				cnt++;
				addedge(source, club[i], 1);
				addedge(tengah + str[i], sink, 1);
			}
		}

	for(int i = 0; i <= las; i++){
		addedge(tengah + i, sink, 1);
	}
	int total = 0;
	while(bfs()){
		for(int i = 0; i <= sink; i++)st[i] = 0;
		while(int flow = dfs(0, 9999999))
			total += flow;
	}
	return (total==cnt);
}
int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++)scanf("%d",&str[i]);
	for(int i = 0; i < n; i++)scanf("%d",&club[i]);
	for(int i = 0; i < n; i++)cek[i] = 1;
	cin >> q;
	source = 0;
	tengah = m + 1;
	sink = tengah + 5000 + 1;
	int las = -1;
	for(int i = 0; i < tengah; i++){
		int temp = maxflow(i);
		if(temp == 0)break;
		las = i;
	}
	int cnt = 0;
	while(q--){
		int x;
		scanf("%d",&x);
		cek[x-1] = 0;
		cnt++;
		while(las >= 0 && maxflow(las) == 0){
			las--;
		}
		int mex = las+1;
		printf("%d\n",mex);
	}
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 1e18
using namespace std;
struct edge{
	long long to, flow, cap, rev;
};
vector<edge>e[20005];
int club[20005], cek[20005]={}, str[20005];
int source, sink, tengah;
int n, m, q;
int st[20005], lvl[20005];
void addedge(long long x, long long y, long long cap){
	edge a = {y, 0, cap, (long long)e[y].size()};
	edge b = {x, 0, 0, (long long)e[x].size()};
	e[x].pb(a);
	e[y].pb(b);
}
long long bfs(){
	for(long long i = 0; i <= sink; i++)lvl[i] = 0;
	lvl[source] = 1;
	queue<long long>q;
	q.push(source);
	while(!q.empty()){
		long long x = q.front();
		q.pop();
		for(long long i =0 ; i < e[x].size(); i++){
			edge ee = e[x][i];
			if(ee.flow < ee.cap && lvl[ee.to] == 0){
				q.push(ee.to);
				lvl[ee.to] = lvl[x]+1;
			}
		}
	}
	return lvl[sink];
}
long long dfs(long long x, long long f){
	if(x == sink)return f;
	for(; st[x] < e[x].size(); st[x]++){
		edge ee = e[x][st[x]];
		if(lvl[ee.to] != lvl[x]+1 || ee.flow == ee.cap)continue;
		long long flow = dfs(ee.to, min(ee.cap - ee.flow, f));
		if(flow){
			e[x][st[x]].flow += flow;
			e[ee.to][ee.rev].flow -= flow;
			return flow;
		}
	}
	return 0;
}
int maxflow(int las){
	int cnt = las+1;
	for(int i = 0; i <= sink; i++)e[i].clear();

	for(int i = 1; i <= m; i++)addedge(source, i, 1);

	for(int i = 0; i < n; i++)
		if(str[i] <= las){
			addedge(club[i], tengah + str[i], 1);
			if(cek[i] == 0){
				cnt++;
				addedge(source, club[i], 1);
				addedge(tengah + str[i], sink, 1);
			}
		}

	for(int i = 0; i <= las; i++){
		addedge(tengah + i, sink, 1);
	}
	int total = 0;
	while(bfs()){
		for(int i = 0; i <= sink; i++)st[i] = 0;
		while(int flow = dfs(0, 9999999))
			total += flow;
	}
	return (total==cnt);
}
int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++)cin >> str[i];
	for(int i = 0; i < n; i++)cin >> club[i];
	for(int i = 0; i < n; i++)cek[i] = 1;
	cin >> q;
	source = 0;
	tengah = m + 1;
	sink = tengah + 5000 + 1;
	int las = -1;
	for(int i = 0; i < tengah; i++){
		int temp = maxflow(i);
		if(temp == 0)break;
		las = i;
	}
	int cnt = 0;
	while(q--){
		int x;
		scanf("%d",&x);
		cek[x-1] = 0;
		cnt++;
		while(las >= 0 && maxflow(las) == 0){
			las--;
		}
		int mex = las+1;
		printf("%d\n",mex);
	}
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 1e18
using namespace std;
struct edge{
	int to, flow, cap, rev;
};
vector<edge>e[20005];
int club[20005], cek[20005]={}, str[20005];
int source, sink, tengah;
int n, m, q;
int st[20005], lvl[20005], arr[20005];
void addedge(int x, int y, int cap){
	edge a = {y, 0, cap, (int)e[y].size()};
	edge b = {x, 0, 0, (int)e[x].size()};
	e[x].pb(a);
	e[y].pb(b);
}
int bfs(){
	for(int i = 0; i <= sink; i++)lvl[i] = 0;
	lvl[source] = 1;
	queue<int>q;
	q.push(source);
	while(!q.empty()){
		int x = q.front();
		q.pop();
		for(int i =0 ; i < e[x].size(); i++){
			edge ee = e[x][i];
			if(ee.flow < ee.cap && lvl[ee.to] == 0){
				q.push(ee.to);
				lvl[ee.to] = lvl[x]+1;
			}
		}
	}
	return lvl[sink];
}
int dfs(int x, int f){
	if(x == sink)return f;
	for(; st[x] < e[x].size(); st[x]++){
		edge ee = e[x][st[x]];
		if(lvl[ee.to] != lvl[x]+1 || ee.flow == ee.cap)continue;
		int flow = dfs(ee.to, min(ee.cap - ee.flow, f));
		if(flow){
			e[x][st[x]].flow += flow;
			e[ee.to][ee.rev].flow -= flow;
			return flow;
		}
	}
	return 0;
}
int maxflow(){
	int total = 0;
	while(bfs()){
		for(int i = 0; i <= sink; i++)st[i] = 0;
		while(int flow = dfs(0, 9999999))
			total += flow;
	}
	return total;
}
int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++)scanf("%d",&str[i]);
	for(int i = 0; i < n; i++)scanf("%d",&club[i]);
	for(int i = 0; i < n; i++)cek[i] = 1;
	cin >> q;
	for(int i = 0; i < q; i++){
		scanf("%d",&arr[i]);
		cek[arr[i]-1] = 0;
	}
	source = 0;
	tengah = m + 1;
	sink = tengah + 5000 + 1;
	int las = 0;
	addedge(tengah, sink, 1);
	vector<int>ans;
	for(int i = 1; i <= m; i++){
		addedge(source, i, 1);
	}
	int sum = 0;
	for(int i = 0; i < n; i++){
		if(cek[i]){
			addedge(club[i], tengah + str[i], 1);
			sum += maxflow();
			while(sum == las+1){
				las++;
				addedge(tengah+las, sink, 1);
				sum += maxflow();
			}
		}
	}
	for(int i = q-1; i >= 0; i--){
		ans.push_back(las);
		addedge(club[arr[i]-1], tengah + str[arr[i]-1], 1);
		sum += maxflow();
		while(sum == las+1){
			las++;
			addedge(tengah+las, sink, 1);
			sum += maxflow();
		}
	}
	for(int i = q-1; i >= 0; i--)cout<<ans[i]<<endl;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 1e18
using namespace std;
struct edge{
	long long to, flow, cap, rev;
};
vector<edge>e[10005];
int club[10005], cek[10005]={}, str[10005];
int source, sink, tengah;
int n, m, q;
int st[10005], lvl[10005];
void addedge(long long x, long long y, long long cap){
	edge a = {y, 0, cap, (long long)e[y].size()};
	edge b = {x, 0, 0, (long long)e[x].size()};
	e[x].pb(a);
	e[y].pb(b);
}
long long bfs(){
	for(long long i = 0; i <= sink; i++)lvl[i] = 0;
	lvl[source] = 1;
	queue<long long>q;
	q.push(source);
	while(!q.empty()){
		long long x = q.front();
		q.pop();
		for(long long i =0 ; i < e[x].size(); i++){
			edge ee = e[x][i];
			if(ee.flow < ee.cap && lvl[ee.to] == 0){
				q.push(ee.to);
				lvl[ee.to] = lvl[x]+1;
			}
		}
	}
	return lvl[sink];
}
long long dfs(long long x, long long f){
	if(x == sink)return f;
	for(; st[x] < e[x].size(); st[x]++){
		edge ee = e[x][st[x]];
		if(lvl[ee.to] != lvl[x]+1 || ee.flow == ee.cap)continue;
		long long flow = dfs(ee.to, min(ee.cap - ee.flow, f));
		if(flow){
			e[x][st[x]].flow += flow;
			e[ee.to][ee.rev].flow -= flow;
			return flow;
		}
	}
	return 0;
}
int maxflow(int x){
	for(int i = 0; i <= sink; i++)e[i].clear();

	for(int i = 1; i <= m; i++)addedge(source, i, 1);
	for(int i = 0; i < n; i++)
		if(cek[i] == 1 && str[i] <= x){
			addedge(club[i], tengah + str[i], 1);
		}
	for(int i = 0; i <= x; i++){
		addedge(tengah + i, sink, 1);
	}
	int total = 0;
	while(bfs()){
		for(int i = 0; i <= sink; i++)st[i] = 0;
		while(int flow = dfs(0, 9999999))
			total += flow;
	}
	if(total == x+1) return 1;
	return 0;
}
int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++)cin >> str[i];
	for(int i = 0; i < n; i++)cin >> club[i];
	for(int i = 0; i < n; i++)cek[i] = 1;
	cin >> q;
	source = 0;
	tengah = m + 1;
	sink = tengah + 5000 + 1;
	while(q--){
		int x;
		cin >> x;
		cek[x-1] = 0;
		int lo = 0, hi = m+1, mid, mex;
		while(lo <= hi){
			mid = (lo+hi)/2;
			if(maxflow(mid) == 1){
				lo = mid + 1;
			}else{
				hi = mid - 1;
				mex = mid;
			}
		}
		cout << mex << endl;
	}
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 1e18
using namespace std;
struct edge{
	long long to, flow, cap, rev;
};
vector<edge>e[10005];
int club[10005], cek[10005]={}, str[10005];
int source, sink, tengah;
int n, m, q;
int st[10005], lvl[10005];
void addedge(long long x, long long y, long long cap){
	edge a = {y, 0, cap, (long long)e[y].size()};
	edge b = {x, 0, 0, (long long)e[x].size()};
	e[x].pb(a);
	e[y].pb(b);
}
long long bfs(){
	for(long long i = 0; i <= sink; i++)lvl[i] = 0;
	lvl[source] = 1;
	queue<long long>q;
	q.push(source);
	while(!q.empty()){
		long long x = q.front();
		q.pop();
		for(long long i =0 ; i < e[x].size(); i++){
			edge ee = e[x][i];
			if(ee.flow < ee.cap && lvl[ee.to] == 0){
				q.push(ee.to);
				lvl[ee.to] = lvl[x]+1;
			}
		}
	}
	return lvl[sink];
}
long long dfs(long long x, long long f){
	if(x == sink)return f;
	for(; st[x] < e[x].size(); st[x]++){
		edge ee = e[x][st[x]];
		if(lvl[ee.to] != lvl[x]+1 || ee.flow == ee.cap)continue;
		long long flow = dfs(ee.to, min(ee.cap - ee.flow, f));
		if(flow){
			e[x][st[x]].flow += flow;
			e[ee.to][ee.rev].flow -= flow;
			return flow;
		}
	}
	return 0;
}
int maxflow(int x){
	for(int i = 0; i <= sink; i++)e[i].clear();

	for(int i = 1; i <= m; i++)addedge(source, i, 1);
	for(int i = 0; i < n; i++)
		if(cek[i] == 1 && str[i] <= x){
			addedge(club[i], tengah + str[i], 1);
		}
	for(int i = 0; i <= x; i++){
		addedge(tengah + i, sink, 1);
	}
	int total = 0;
	while(bfs()){
		for(int i = 0; i <= sink; i++)st[i] = 0;
		while(int flow = dfs(0, 9999999))
			total += flow;
	}
	if(total == x+1) return 1;
	return 0;
}
int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++)cin >> str[i];
	for(int i = 0; i < n; i++)cin >> club[i];
	for(int i = 0; i < n; i++)cek[i] = 1;
	cin >> q;
	source = 0;
	tengah = m + 1;
	sink = tengah + 5000 + 1;
	int las = m+1;
	while(q--){
		int x;
		cin >> x;
		cek[x-1] = 0;
		int lo = 0, hi = las, mid, mex;
		while(lo <= hi){
			mid = (lo+hi)/2;
			if(maxflow(mid) == 1){
				lo = mid + 1;
			}else{
				hi = mid - 1;
				mex = mid;
			}
		}
		las = mex;
		cout << mex << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define inf 0x7f7f7f7f
#define Maxn 10005
typedef long long ll;
inline int rd()
{
	 int x=0;
     char ch,t=0;
     while(!isdigit(ch = getchar())) t|=ch=='-';
     while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
     return x=t?-x:x;
}
int n,m,d,tot;
int hea[Maxn],nex[Maxn*2],ver[Maxn*2];
int p[Maxn],c[Maxn],r[Maxn],match[Maxn],ans[Maxn],rec[Maxn];
bool vis[Maxn];
inline void add(int x,int y)
{
	 ver[++tot]=y,nex[tot]=hea[x],hea[x]=tot;
}
bool dfs(int x)
{
	 for(int i=hea[x];i;i=nex[i]) if(!vis[ver[i]])
	 {
	 	 vis[ver[i]]=true;
	 	 if(match[ver[i]]==-1 || dfs(match[ver[i]]))
	 	 {
	 	 	 match[ver[i]]=x; return true;
		 }
	 }
	 return false;
}
int main()
{
     //freopen(".in","r",stdin);
     //freopen(".out","w",stdout);
	 n=rd(),m=rd();
	 for(int i=1;i<=n;i++) p[i]=min(rd(),m);
	 for(int i=1;i<=n;i++) c[i]=rd();
	 d=rd();
	 for(int i=1;i<=n;i++) r[i]=d+1;
	 for(int i=1;i<=d;i++) rec[i]=rd(),r[rec[i]]=i;
	 for(int i=1;i<=n;i++) if(r[i]>d) add(p[i],c[i]+m),add(c[i]+m,p[i]);
	 memset(match,-1,sizeof(match));
	 for(int i=d;i>=1;i--)
	 {
	 	 for(int j=ans[i+1];j<=m;j++)
		 {
	 	 	 memset(vis,false,sizeof(vis));
		 	 if(!dfs(j)){ ans[i]=j; break; }
		 }
	 	 add(p[rec[i]],c[rec[i]]+m),add(c[rec[i]]+m,p[rec[i]]);
	 }
	 for(int i=1;i<=d;i++) printf("%d\n",ans[i]);
     //fclose(stdin);
     //fclose(stdout);
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 0x7f7f7f7f
#define Maxn 10005
typedef long long ll;
inline int rd()
{
	 int x=0;
     char ch,t=0;
     while(!isdigit(ch = getchar())) t|=ch=='-';
     while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
     return x=t?-x:x;
}
int n,m,d,tot;
int hea[Maxn],nex[Maxn*2],ver[Maxn*2];
int p[Maxn],c[Maxn],r[Maxn],match[Maxn],ans[Maxn],rec[Maxn];
bool vis[Maxn];
inline void add(int x,int y)
{
	 ver[++tot]=y,nex[tot]=hea[x],hea[x]=tot;
}
bool dfs(int x)
{
	 for(int i=hea[x];i;i=nex[i]) if(!vis[ver[i]])
	 {
	 	 vis[ver[i]]=true;
	 	 if(match[ver[i]]==-1 || dfs(match[ver[i]]))
	 	 {
	 	 	 match[ver[i]]=x; return true;
		 }
	 }
	 return false;
}
int main()
{
     //freopen(".in","r",stdin);
     //freopen(".out","w",stdout);
	 n=rd(),m=rd();
	 for(int i=1;i<=n;i++) p[i]=min(rd(),m);
	 for(int i=1;i<=n;i++) c[i]=rd();
	 d=rd();
	 for(int i=1;i<=n;i++) r[i]=d+1;
	 for(int i=1;i<=d;i++) rec[i]=rd(),r[rec[i]]=i;
	 for(int i=1;i<=n;i++) if(r[i]>d) add(p[i],c[i]+m),add(c[i]+m,p[i]);
	 for(int i=d;i>=1;i--)
	 {
	 	 memset(match,-1,sizeof(match));
	 	 for(int j=0;j<=m;j++)
		 {
	 	 	 memset(vis,false,sizeof(vis));
		 	 if(!dfs(j)){ ans[i]=j; break; }
		 }
	 	 add(p[rec[i]],c[rec[i]]+m),add(c[rec[i]]+m,p[rec[i]]);
	 }
	 for(int i=1;i<=d;i++) printf("%d\n",ans[i]);
     //fclose(stdin);
     //fclose(stdout);
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 0x7f7f7f7f
#define Maxn 10005
typedef long long ll;
inline int rd()
{
	 int x=0;
     char ch,t=0;
     while(!isdigit(ch = getchar())) t|=ch=='-';
     while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
     return x=t?-x:x;
}
int n,m,d,tot;
int hea[Maxn],nex[Maxn*2],ver[Maxn*2];
int p[Maxn],c[Maxn],r[Maxn],match[Maxn],ans[Maxn],rec[Maxn];
bool vis[Maxn];
inline void add(int x,int y)
{
	 ver[++tot]=y,nex[tot]=hea[x],hea[x]=tot;
}
bool dfs(int x)
{
	 for(int i=hea[x];i;i=nex[i]) if(!vis[ver[i]])
	 {
	 	 vis[ver[i]]=true;
	 	 if(match[ver[i]]==-1 || dfs(match[ver[i]]))
	 	 {
	 	 	 match[ver[i]]=x; return true;
		 }
	 }
	 return false;
}
int main()
{
     //freopen(".in","r",stdin);
     //freopen(".out","w",stdout);
	 n=rd(),m=rd();
	 for(int i=1;i<=n;i++) p[i]=min(rd(),m);
	 for(int i=1;i<=n;i++) c[i]=rd();
	 d=rd();
	 for(int i=1;i<=n;i++) r[i]=d+1;
	 for(int i=1;i<=d;i++) rec[i]=rd(),r[rec[i]]=i;
	 for(int i=1;i<=n;i++) if(r[i]>d) add(p[i],c[i]+m),add(c[i]+m,p[i]);
	 for(int i=d;i>=1;i--)
	 {
	 	 memset(match,-1,sizeof(match));
	 	 for(int j=ans[i+1];j<=m;j++)
		 {
	 	 	 memset(vis,false,sizeof(vis));
		 	 if(!dfs(j)){ ans[i]=j; break; }
		 }
	 	 add(p[rec[i]],c[rec[i]]+m),add(c[rec[i]]+m,p[rec[i]]);
	 }
	 for(int i=1;i<=d;i++) printf("%d\n",ans[i]);
     //fclose(stdin);
     //fclose(stdout);
     return 0;
}


/**************************************************************
    Problem: ????
    User: Big_Red_Dates
    Language: GNU_C++11
    Result: Accepted
    Time:0 ms
    Memory:0 kb
    length:0 kb
    score: inf
****************************************************************/
//CLOCKS_PER_SEC
using namespace std;
#include<bitset>
#include<deque>
#include<stdint.h>
#include<set>
#include<stack>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<ctime>
#include<map>
#define sqr(x) (x)*(x)
#define sort stable_sort
#define ll long long
#define mk make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mk(mk(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#define all(x) (x).begin(),(x).end()
#define titose CLOCKS_PER_SEC
#define fpi(x) freopen(x,"r",stdin);
#define fpo(x) freopen(x,"w",stdout);
#define fprio fpi("in.txt");fpo("out.txt");
#define fast ios_base::sync_with_stdio(false);
inline void read(int &x){int v=0,f=1;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=v*10+c-'0';while (isdigit(c=getchar())) v=v*10+c-'0';x=v*f;}
inline void read(ll &x){ll v=0ll,f=1ll;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=v*10+c-'0';while (isdigit(c=getchar())) v=v*10+c-'0';x=v*f;}
inline void readc(char &x){char c;while ((c=getchar())==' ');x=c;}
inline void writes(string s){puts(s.c_str());}
inline void writeln(){writes("");}
inline void writei(int x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
inline void writell(ll x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
#define sl set<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define msi map<string,int>
#define msl map<string,ll>
#define piii pair<int,pii >
#define piipi pair<pii,int>
#define plll pair<ll,pll >
#define pllpl pair<pll,ll>
#define pqi priority_queue<int>
#define pql priority_queue<ll>
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define forup(i,csc,lys) for ((i)=(csc);(i)<=(lys);(i)++)
#define fordo(i,csc,lys) for ((i)=(csc);(i)>=(lys);(i)--)
#define rep(i,x) forup ((i),1,(x))
#define repd(i,x) fordo ((i),(x),1)
#define itr iterator
#define lyscsc(itcalc,c) for(__typeof((c).begin()) itcalc=(c).begin();itcalc!=(c).end();itcalc++)
#define NO {cout<<"NO";return 0;}
#define YES {cout<<"YES";return 0;}
#define y0 y000000000000000000000000000
#define y1 y111111111111111111111111111
#define j0 j000000000000000000000000000
#define j1 j111111111111111111111111111
#define cl0(a) memset((a),(0),(sizeof((a))))
#define clz(a) memset((a),(0x16),(sizeof((a))))
#define clf(a) memset((a),(-(0x16)),(sizeof((a))))
#define inf 0x3bbbbbbb
#define lnf 0x1bbbbbbbbbbbbbbbll
#define sqrt divi
#define p2(i) (1ll<<(i))
#define readi read
#define readll read
/*************************************************/
int n,m,d,i,j,x,y,a[5005],b[5005],v[5005],lk[5005],ans;
vector<int> e[5005],f[5005],s;
bool lys_try(int x)
{
	if (v[x]) return 0;
	v[x]=1;
	lyscsc(it,e[x])
	{
		if (lk[*it]==-1||lys_try(lk[*it]))
		{
			lk[*it]=x;
			return 1;
		}
	}
	return 0;
}
int main()
{
	fast;
	cin>>n>>m;
	rep(i,n)
	{
		cin>>a[i];
	}
	rep(i,n)
	{
		cin>>b[i];
	}
	cin>>d;
	rep(i,d)
	{
		cin>>x;
		f[i-1].push_back(x);
		v[x]=1;
	}
	rep(i,n) if (!v[i])
	{
		f[d].pb(i);
	}
	memset(lk,-1,sizeof(lk));
	repd(i,d)
	{
		lyscsc(it,f[i])
		{
			e[a[*it]].pb(b[*it]);
		}
		memset(v,0,sizeof(v));
		while (lys_try(ans))
		{
			ans++;
			memset(v,0,sizeof(v));
		}
		s.pb(ans);
	}
	reverse(all(s));
	lyscsc(it,s) cout<<*it<<endl;
	return 0;
}


/**************************************************************
    Problem: ????
    User: Big_Red_Dates
    Language: GNU_C++11
    Result: Accepted
    Time:0 ms
    Memory:0 kb
    length:0 kb
    score: inf
****************************************************************/
//CLOCKS_PER_SEC
using namespace std;
#include<bitset>
#include<deque>
#include<stdint.h>
#include<set>
#include<stack>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<ctime>
#include<map>
#define sqr(x) (x)*(x)
#define sort stable_sort
#define ll long long
#define mk make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mk(mk(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#define all(x) (x).begin(),(x).end()
#define titose CLOCKS_PER_SEC
#define fpi(x) freopen(x,"r",stdin);
#define fpo(x) freopen(x,"w",stdout);
#define fprio fpi("in.txt");fpo("out.txt");
#define fast ios_base::sync_with_stdio(false);
inline void read(int &x){int v=0,f=1;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=v*10+c-'0';while (isdigit(c=getchar())) v=v*10+c-'0';x=v*f;}
inline void read(ll &x){ll v=0ll,f=1ll;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=v*10+c-'0';while (isdigit(c=getchar())) v=v*10+c-'0';x=v*f;}
inline void readc(char &x){char c;while ((c=getchar())==' ');x=c;}
inline void writes(string s){puts(s.c_str());}
inline void writeln(){writes("");}
inline void writei(int x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
inline void writell(ll x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
#define sl set<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define msi map<string,int>
#define msl map<string,ll>
#define piii pair<int,pii >
#define piipi pair<pii,int>
#define plll pair<ll,pll >
#define pllpl pair<pll,ll>
#define pqi priority_queue<int>
#define pql priority_queue<ll>
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define forup(i,csc,lys) for ((i)=(csc);(i)<=(lys);(i)++)
#define fordo(i,csc,lys) for ((i)=(csc);(i)>=(lys);(i)--)
#define rep(i,x) forup ((i),1,(x))
#define repd(i,x) fordo ((i),(x),1)
#define itr iterator
#define lyscsc(itcalc,c) for(__typeof((c).begin()) itcalc=(c).begin();itcalc!=(c).end();itcalc++)
#define NO {cout<<"NO";return 0;}
#define YES {cout<<"YES";return 0;}
#define y0 y000000000000000000000000000
#define y1 y111111111111111111111111111
#define j0 j000000000000000000000000000
#define j1 j111111111111111111111111111
#define cl0(a) memset((a),(0),(sizeof((a))))
#define clz(a) memset((a),(0x16),(sizeof((a))))
#define clf(a) memset((a),(-(0x16)),(sizeof((a))))
#define inf 0x3bbbbbbb
#define lnf 0x1bbbbbbbbbbbbbbbll
#define sqrt divi
#define p2(i) (1ll<<(i))
#define readi read
#define readll read
/*************************************************/
int n,m,d,i,j,x,y,a[5005],b[5005],v[5005],lk[5005],ans;
vector<int> e[5005],f[5005],s;
bool lys_try(int x)
{
	if (v[x]) return 0;
	v[x]=1;
	lyscsc(it,e[x])
	{
		if (lk[*it]==-1||lys_try(lk[*it]))
		{
			lk[*it]=x;
			return 1;
		}
	}
	return 0;
}
int main()
{
	fast;
	cin>>n>>m;
	rep(i,n)
	{
		cin>>a[i];
	}
	rep(i,n)
	{
		cin>>b[i];
	}
	cin>>d;
	rep(i,d)
	{
		cin>>x;
		f[i-1].push_back(x);
		v[x]=1;
	}
	rep(i,n) if (!v[i])
	{
		f[n].pb(i);
	}
	memset(lk,-1,sizeof(lk));
	repd(i,n)
	{
		lyscsc(it,f[i])
		{
			e[a[*it]].pb(b[*it]);
		}
		memset(v,0,sizeof(v));
		while (lys_try(ans))
		{
			ans++;
			memset(v,0,sizeof(v));
		}
		s.pb(ans);
	}
	reverse(all(s));
	lyscsc(it,s) cout<<*it<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, m, Assigned[5010];
int Visited[5010], t = 0;
int ok[5010],d[5010],c[5010];
int tv[5010];
vector<int> a[5010];
bool visit(int u) {
    if (Visited[u] != t)
        Visited[u] = t;
    else
        return false;

    for (int i = 0; i < a[u].size(); i++) {
        int v = a[u][i];
        if (!Assigned[v] ) {
            Assigned[v] = u;
            return true;
        }
    }
    for (int i = 0; i < a[u].size(); i++) {
        int v = a[u][i];
        if (visit(Assigned[v])) {
            Assigned[v] = u;
            return true;
        }
    }
    return false;
}
main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>d[i];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>c[i];
    }
    int L;
    cin>>L;
    for(int i=1;i<=L;i++)
    {
        cin>>tv[i];
        ok[tv[i]]=1;
    }
    for(int i=1;i<=n;i++)
    {
        if(ok[i]==0)
        {
            a[d[i]].push_back(c[i]);
        }
    }
    int cur=0;
    stack<int>s;
    for(int i=L;i>=1;i--)
    {
        for(int j=cur;j<=5000;j++)
        {
            t++;
            if(!visit(j))
            {
                s.push(j);
                cur=j;
                break;
            }
        }
        a[d[tv[i]]].push_back(c[tv[i]]);
    }
    while(s.size())
    {
        cout<<s.top()<<'\n';
        s.pop();
    }
}


#include<bits/stdc++.h>
using namespace std;
int n, m, Assigned[5010];
int Visited[5010], t = 0;
int ok[5010],d[5010],c[5010];
int tv[5010];
vector<int> a[5010];
bool visit(int u) {
    if (Visited[u] != t)
        Visited[u] = t;
    else
        return false;

    for (int i = 0; i < a[u].size(); i++) {
        int v = a[u][i];
        if (!Assigned[v] ) {
            Assigned[v] = u;
            return true;
        }
    }
    for (int i = 0; i < a[u].size(); i++) {
        int v = a[u][i];
        if (visit(Assigned[v])) {
            Assigned[v] = u;
            return true;
        }
    }
    return false;
}
main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>d[i];
        d[i]++;
    }
    for(int i=1;i<=n;i++)
    {
        cin>>c[i];
    }
    int L;
    cin>>L;
    for(int i=1;i<=L;i++)
    {
        cin>>tv[i];
        ok[tv[i]]=1;
    }
    for(int i=1;i<=n;i++)
    {
        if(ok[i]==0)
        {
            a[d[i]].push_back(c[i]);
        }
    }
    int cur=1;
    stack<int>s;
    for(int i=L;i>=1;i--)
    {
        for(int j=cur;j<=5001;j++)
        {
            t++;
            if(!visit(j))
            {
                s.push(j-1);
                cur=j;
                break;
            }
        }
        a[d[tv[i]]].push_back(c[tv[i]]);
    }
    while(s.size())
    {
        cout<<s.top()<<'\n';
        s.pop();
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=50100,maxm=maxn;
int n,m,d,vis[maxn],pd[maxn],ans[maxn];
int cnt,bg[maxn],ne[maxm],to[maxm];
int p[maxn],c[maxn],k[maxn];
void add(int x,int y){
	cnt++;
	ne[cnt]=bg[x];
	to[cnt]=y;
	bg[x]=cnt;
}
bool dfs(int x){
	for(int i=bg[x];i;i=ne[i]){
		int y=to[i];
		if(vis[y]==0){
			vis[y]=1;
			if(pd[y]==-1||dfs(pd[y])){
				pd[y]=x;
				return 1;
			}
		}
	}
	return 0;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		scanf("%d",&p[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&c[i]);
	}
	cin>>d;
	for(int i=1;i<=d;i++){
		scanf("%d",&k[i]);
		vis[k[i]]=1;
	}
	for(int i=1;i<=n;i++){
		if(vis[i]==0){
			add(p[i],c[i]);
		}
	}
	memset(pd,-1,sizeof(pd));
	int sum=0;
	for(int i=d;i>=1;i--){
		memset(vis,0,sizeof(vis));
		while(dfs(sum)==1){
			sum++;
			memset(vis,0,sizeof(vis));
		}
		ans[i]=sum;
		add(p[k[i]],c[k[i]]);
	}
	for(int i=1;i<=d;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=50100,maxm=maxn;
int n,m,d,vis[maxn],pd[maxn],ans[maxn];
int cnt,bg[maxn],ne[maxm],to[maxm];
int p[maxn],c[maxn],k[maxn];
void add(int x,int y){
	cnt++;
	ne[cnt]=bg[x];
	to[cnt]=y;
	bg[x]=cnt;
}
bool dfs(int x){
	for(int i=bg[x];i;i=ne[i]){
		int y=to[i];
		if(vis[y]==0){
			vis[y]=1;
			if(pd[y]==0||dfs(pd[y])){
				pd[y]=x;
				return 1;
			}
		}
	}
	return 0;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		scanf("%d",&p[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&c[i]);
	}
	cin>>d;
	for(int i=1;i<=d;i++){
		scanf("%d",&k[i]);
		vis[k[i]]=1;
	}
	for(int i=1;i<=n;i++){
		if(vis[i]==0){
			add(p[i],c[i]);
		}
	}
	memset(vis,0,sizeof(vis));
	int sum=0;
	for(int i=d;i>=1;i--){
		while(dfs(sum)==1){
			sum++;
			memset(vis,0,sizeof(vis));
		}
		ans[i]=sum;
		add(p[k[i]],c[k[i]]);
	}
	for(int i=1;i<=d;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5010,maxm=maxn;
int n,m,d,vis[maxn],pd[maxn],ans[maxn];
int cnt,bg[maxn],ne[maxm],to[maxm];
int p[maxn],c[maxn],k[maxn];
void add(int x,int y){
	cnt++;
	ne[cnt]=bg[x];
	to[cnt]=y;
	bg[x]=cnt;
}
bool dfs(int x){
	for(int i=bg[x];i;i=ne[i]){
		int y=to[i];
		if(vis[y]==0){
			vis[y]=1;
			if(pd[y]==0||dfs(pd[y])){
				pd[y]=x;
				return 1;
			}
		}
	}
	return 0;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		scanf("%d",&p[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&c[i]);
	}
	cin>>d;
	for(int i=1;i<=d;i++){
		scanf("%d",&k[i]);
		vis[k[i]]=1;
	}
	for(int i=1;i<=n;i++){
		if(vis[i]==0){
			add(p[i],c[i]);
		}
	}
	int sum=0;
	for(int i=d;i>=1;i--){
		memset(vis,0,sizeof(vis));
		while(dfs(sum)==1){
			sum++;
			memset(vis,0,sizeof(vis));
		}
		ans[i]=sum;
		add(p[k[i]],c[k[i]]);
	}
	for(int i=1;i<=d;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = 10005;
int k[N], p[N], c[N];
int read(void) {
    int x = 0; char c = getchar();
    while (!isdigit(c)) c = getchar();
    for (;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^48);
    return x;
}

int h[N], ne[N<<1], to[N<<1];
int d, n, m, tot;
inline void add(int x,int y) {
    ne[++tot] = h[x], to[tot] = y;
    h[x] = tot;
}

int vis[N], tim;
int match[N], used[N];
bool dfs(int x) {
    for (int i = h[x]; i; i = ne[i]) {
        int y = to[i]; if (vis[y] == tim) continue;
        vis[y] = tim;
        if (!match[y] || dfs(match[y])) {
            match[y] = x; return used[x] = true;
        }
    }
    return false;
}

int ans[N], v[N];
int main() {
    n = read(), m = read();
    for (int i = 1;i <= n; i++) p[i] = read();
    for (int i = 1;i <= n; i++) c[i] = read();
    int pre = -1, nw;
    d = read();
    for (int i = 1;i <= d; i++) k[i] = read(), v[k[i]] = 1;
    for (int i = 1;i <= n; i++)
        if (!v[i]) add(p[i], c[i]);
    for (int i = d;i >= 1; i--) {
        for (nw = pre + 1;nw <= n; nw++) {
            if (used[nw]) continue;
            tim++; if (!dfs(nw)) break;
        }
        add(p[k[i]], c[k[i]]);
        ans[i] = nw; pre = nw - 1;
    }
    for (int i = 1;i <= d; i++) printf ("%d\n", ans[i]);
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = 10005;
int k[N], p[N], c[N];
int read(void) {
    int x = 0; char c = getchar();
    while (!isdigit(c)) c = getchar();
    for (;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^48);
    return x;
}

int h[N], ne[N<<1], to[N<<1];
int d, n, m, tot;
inline void add(int x,int y) {
    ne[++tot] = h[x], to[tot] = y;
    h[x] = tot;
}

int vis[N], tim;
int match[N];
bool dfs(int x) {
    for (int i = h[x]; i; i = ne[i]) {
        int y = to[i]; if (vis[y] == tim) continue;
        vis[y] = tim;
        if (!(~match[y]) || dfs(match[y])) {
            match[y] = x; return true;
        }
    }
    return false;
}

int ans[N], v[N];
int main() {
    n = read(), m = read();
    memset(match, -1, sizeof(match));
    for (int i = 1;i <= n; i++) p[i] = read();
    for (int i = 1;i <= n; i++) c[i] = read();
    int pre = -1, nw;
    d = read();
    for (int i = 1;i <= d; i++) k[i] = read(), v[k[i]] = 1;
    for (int i = 1;i <= n; i++)
        if (!v[i] && c[i] <= m) add(p[i], c[i]);
    for (int i = d;i >= 1; i--) {
        for (nw = pre + 1;nw <= n; nw++) {
            tim++; if (!dfs(nw)) break;
        }
        if (c[i] <= m) add(p[k[i]], c[k[i]]);
        ans[i] = nw; pre = nw - 1;
    }
    for (int i = 1;i <= d; i++) printf ("%d\n", ans[i]);
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = 10005;
int k[N], p[N], c[N];
int read(void) {
    int x = 0; char c = getchar();
    while (!isdigit(c)) c = getchar();
    for (;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^48);
    return x;
}

int h[N], ne[N<<1], to[N<<1];
int d, n, m, tot;
inline void add(int x,int y) {
    ne[++tot] = h[x], to[tot] = y;
    h[x] = tot;
}

int vis[N], tim;
int match[N];
bool dfs(int x) {
    for (int i = h[x]; i; i = ne[i]) {
        int y = to[i]; if (vis[y] == tim) continue;
        vis[y] = tim;
        if (!match[y] || dfs(match[y])) {
            match[y] = x; return true;
        }
    }
    return false;
}

int ans[N], v[N];
int main() {
    n = read(), m = read();
    for (int i = 1;i <= n; i++) p[i] = read();
    for (int i = 1;i <= n; i++) c[i] = read();
    int pre = -1, nw;
    d = read();
    for (int i = 1;i <= d; i++) k[i] = read(), v[k[i]] = 1;
    for (int i = 1;i <= n; i++)
        if (!v[i] && c[i] <= m) add(p[i], c[i]);
    for (int i = d;i >= 1; i--) {
        for (nw = pre + 1;nw <= n; nw++) {
            tim++; if (!dfs(nw)) break;
        }
        if (c[i] <= m) add(p[k[i]], c[k[i]]);
        ans[i] = nw; pre = nw - 1;
    }
    for (int i = 1;i <= d; i++) printf ("%d\n", ans[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 5005;
struct node{
    int x, id;
    node(int x1, int i){
        x = x1;
        id = i;
    }
};

int vis[maxn], p[maxn], c[maxn], k[maxn], can[maxn][maxn];
vector<node> s[maxn];

bool cmp(const node &a1, const node &a2){
    return a1.x < a2.x;
}
vector<int> ans, q;
int pre[maxn];

bool dfs(int x, int n){
    for(int i = 1; i <= n; i++){
        if(can[x][i] == 1 && !vis[i]){
            vis[i] = 1;
            q.push_back(i);
            if(pre[i] == -1 || dfs(pre[i], n)){
                pre[i] = x;
                return true;
            }
        }
    }
    return false;
}

bool cou(int now, int n){
    q.clear();
    bool temp = dfs(now, n);
    for(int i = 0; i < q.size(); i++)
        vis[q[i]] = 0;
    return temp;
}

int main(){
    int n, m, d;
    for(int i = 0; i < maxn; i++)
        pre[i] = -1;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++)
        scanf("%d", &p[i]);
    for(int i = 1; i <= n; i++){
        scanf("%d", &c[i]);
    }
    scanf("%d", &d);
    for(int i = 1; i <= d; i++){
        scanf("%d", &k[i]);
        vis[k[i]] = 1;
    }
    for(int i = 1; i <= n; i++){
        if(vis[i] == 1)
            continue;
        can[p[i]][c[i]] = 1;
    }
    memset(vis, 0, sizeof(vis));
    int now = 0;
    for(int i = d; i >= 1; i--){
        while(1){
            if(cou(now, n))
                now++;
            else
                break;
        }
        ans.push_back(now);
        can[p[k[i]]][c[k[i]]] = 1;
    }
    for(int i = 0; i < ans.size(); i++)
        printf("%d\n", ans[ans.size() - i - 1]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 5005;
struct node{
    int x, id;
    node(int x1, int i){
        x = x1;
        id = i;
    }
};

int vis[maxn], p[maxn], c[maxn], k[maxn], can[maxn][maxn];
vector<node> s[maxn];

bool cmp(const node &a1, const node &a2){
    return a1.x < a2.x;
}
vector<int> ans;
int pre[maxn];

bool dfs(int x, int n){
    for(int i = 1; i <= n; i++){
        if(can[x][i] == 1 && !vis[i]){
            vis[i] = 1;
            if(pre[i] == -1 || dfs(pre[i], n)){
                pre[i] = x;
                return true;
            }
        }
    }
    return false;
}

bool cou(int now, int n, int cc){
    for(int i = 0; i <= n; i++){
        pre[i] = -1;
    }
    for(int i = 0; i <= now; i++){
        memset(vis, 0, sizeof(vis));
        if(dfs(i, n))
            continue;
        else
            return false;
    }
    return true;
}

int main(){
    int n, m, d;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++)
        scanf("%d", &p[i]);
    for(int i = 1; i <= n; i++){
        scanf("%d", &c[i]);
    }
    scanf("%d", &d);
    for(int i = 1; i <= d; i++){
        scanf("%d", &k[i]);
        vis[k[i]] = 1;
    }
    for(int i = 1; i <= n; i++){
        if(vis[i] == 1)
            continue;
        can[p[i]][c[i]] = 1;
    }
    int now = 0;
    for(int i = d; i >= 1; i--){
        while(1){
            if(cou(now, n, i))
                now++;
            else
                break;
        }
        ans.push_back(now);
//        printf("%d @@ %d %d\n", k[i], p[k[i]], c[k[i]]);
        can[p[k[i]]][c[k[i]]] = 1;
    }
    for(int i = 0; i < ans.size(); i++)
        printf("%d\n", ans[ans.size() - i - 1]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 5005;
struct node{
    int x, id;
    node(int x1, int i){
        x = x1;
        id = i;
    }
};

int vis[maxn], p[maxn], c[maxn], k[maxn], can[maxn][maxn];
vector<node> s[maxn];

bool cmp(const node &a1, const node &a2){
    return a1.x < a2.x;
}
vector<int> ans;
int pre[maxn];

bool dfs(int x, int n){
    for(int i = 1; i <= n; i++){
        if(can[x][i] == 1 && !vis[i]){
            vis[i] = 1;
            if(pre[i] == -1 || dfs(pre[i], n)){
                pre[i] = x;
                return true;
            }
        }
    }
    return false;
}

bool cou(int now, int n){
    memset(vis, 0, sizeof(vis));
    if(dfs(now, n))
        return true;
    return false;
}

int main(){
    int n, m, d;
    for(int i = 0; i < maxn; i++)
        pre[i] = -1;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++)
        scanf("%d", &p[i]);
    for(int i = 1; i <= n; i++){
        scanf("%d", &c[i]);
    }
    scanf("%d", &d);
    for(int i = 1; i <= d; i++){
        scanf("%d", &k[i]);
        vis[k[i]] = 1;
    }
    for(int i = 1; i <= n; i++){
        if(vis[i] == 1)
            continue;
        can[p[i]][c[i]] = 1;
    }
    int now = 0;
    for(int i = d; i >= 1; i--){
        while(1){
            if(cou(now, n))
                now++;
            else
                break;
        }
        ans.push_back(now);
        can[p[k[i]]][c[k[i]]] = 1;
    }
    for(int i = 0; i < ans.size(); i++)
        printf("%d\n", ans[ans.size() - i - 1]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 5005;
struct node{
    int x, id;
    node(int x1, int i){
        x = x1;
        id = i;
    }
};

int vis[maxn], p[maxn], c[maxn], k[maxn];
vector<node> s[maxn];
vector<int> can[maxn];

bool cmp(const node &a1, const node &a2){
    return a1.x < a2.x;
}
vector<int> ans;
int pre[maxn];

bool dfs(int x, int n){
    for(int i = 0; i < can[x].size(); i++){
        int u = can[x][i];
        if(!vis[u]){
            vis[u] = 1;
            if(pre[u] == -1 || dfs(pre[u], n)){
                pre[u] = x;
                return true;
            }
        }
    }
    return false;
}

bool cou(int now, int n){
    memset(vis, 0, sizeof(vis));
    bool temp = dfs(now, n);
    return temp;
}

int main(){
    int n, m, d;
    for(int i = 0; i < maxn; i++)
        pre[i] = -1;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++)
        scanf("%d", &p[i]);
    for(int i = 1; i <= n; i++){
        scanf("%d", &c[i]);
    }
    scanf("%d", &d);
    for(int i = 1; i <= d; i++){
        scanf("%d", &k[i]);
        vis[k[i]] = 1;
    }
    for(int i = 1; i <= n; i++){
        if(vis[i] == 1)
            continue;
        can[p[i]].push_back(c[i]);
    }
    memset(vis, 0, sizeof(vis));
    int now = 0;
    for(int i = d; i >= 1; i--){
        while(1){
            if(cou(now, n))
                now++;
            else
                break;
        }
        ans.push_back(now);
        can[p[k[i]]].push_back(c[k[i]]);
    }
    for(int i = 0; i < ans.size(); i++)
        printf("%d\n", ans[ans.size() - i - 1]);
    return 0;
}


#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=10002,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}

int num[5020][5020],bian[5020][5020];
int a[5200],b[5200];
int match[N];
bool vis[N];
bool mark[N];
bool dfs(int x){
    for(int i=head[x],y;i;i=NEXT[i]){
        if(mark[i]) continue;
        if(!vis[y=ver[i]]){
            vis[y]=true;
            if(!match[y]||dfs(match[y])){
                match[y]=x;
                return true;
            }
        }
    }
}
void er_tu(){
    int ans=0;
    memset(match,0,sizeof(match));
    for(int i=0;i<=5000;i++){
        memset(vis,0,sizeof(vis));
        if(dfs(i)) ans++;
        else break;
    }
    printf("%d\n",ans);

}
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int n,m;
    tot=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++){
        scanf("%d",&b[i]);
        num[b[i]][a[i]]++;
    }
    for(int i=1;i<=m;i++){
        for(int j=0;j<=5000;j++){
            if(num[i][j]) {
                link(j,i+5000);
                bian[i][j]=tot;
            }
        }
    }
    int q,inp;
    scanf("%d",&q);
    while(q--){
        scanf("%d",&inp);
        num[b[inp]][a[inp]]--;
        if(num[b[inp]][a[inp]]==0){
            int tmp=bian[b[inp]][a[inp]];
            //cout<<tmp<<endl;
            mark[tmp]=true;
            er_tu();
        }
    }
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=100002,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}

int num[5020][5020],bian[5020][5020];
int a[5200],b[5200];
int match[10002];
bool vis[10002];
bool mark[N];
bool dfs(int x){
    for(int i=head[x],y;i;i=NEXT[i]){
        if(mark[i]) continue;
        if(!vis[y=ver[i]]){
            vis[y]=true;
            if(!match[y]||dfs(match[y])){
                match[y]=x;
                return true;
            }
        }
    }
}
void er_tu(){
    int ans=0;
    memset(match,0,sizeof(match));
    for(int i=0;i<=5000;i++){
        memset(vis,0,sizeof(vis));
        if(dfs(i)) ans++;
        else break;
    }
    printf("%d\n",ans);

}
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int n,m;
    tot=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++){
        scanf("%d",&b[i]);
        num[b[i]][a[i]]++;
    }
    for(int i=1;i<=m;i++){
        for(int j=0;j<=5000;j++){
            if(num[i][j]) {
                link(j,i+5000);
                bian[i][j]=tot;
            }
        }
    }
    int q,inp;
    scanf("%d",&q);
    while(q--){
        scanf("%d",&inp);
        num[b[inp]][a[inp]]--;
        if(num[b[inp]][a[inp]]==0){
            int tmp=bian[b[inp]][a[inp]];
            //cout<<tmp<<endl;
            mark[tmp]=true;
            er_tu();
        }
    }
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=100002,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}

int ans[5200];
int num[5020][5020],bian[5020][5020];
int a[5200],b[5200];
int match[10002];
bool vis[10002];
bool mark[N];
bool dfs(int x){
    for(int i=head[x],y;i;i=NEXT[i]){
        if(mark[i]) continue;
        if(!vis[y=ver[i]]){
            vis[y]=true;
            if(!match[y]||dfs(match[y])){
                match[y]=x;
                return true;
            }
        }
    }
}
void er_tu(){
    int ans=0;
    memset(match,0,sizeof(match));
    for(int i=0;i<=5000;i++){
        memset(vis,0,sizeof(vis));
        if(dfs(i)) ans++;
        else break;
    }
    printf("%d\n",ans);

}
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++){
        scanf("%d",&b[i]);
        num[b[i]][a[i]]++;
    }
    for(int i=1;i<=m;i++){
        for(int j=0;j<=5000;j++){
            if(num[i][j]) {
                link(j,i+5000);
                bian[i][j]=tot;
            }
        }
    }
    int q,inp;
    scanf("%d",&q);
    while(q--){
        scanf("%d",&inp);
        num[b[inp]][a[inp]]--;
        if(num[b[inp]][a[inp]]==0){
            int tmp=bian[b[inp]][a[inp]];
            //cout<<tmp<<endl;
            mark[tmp]=true;
            er_tu();
        }
    }
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=10002,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//ÄæÔª
int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}

int num[5020][5020],bian[5020][5020];
int a[5200],b[5200];
int match[N];
int linky[N],linkx[N],dy[N],dx[N];
bool vis[N];
bool mark[N];
bool bfs(){
    bool flag=false;
    queue<int>q;
    memset(dx,-1,sizeof(dx));
    memset(dy,-1,sizeof(dy));
    for(int i=0;i<=5000;i++){
        if(linkx[i]==-1){
            q.push(i);
            dx[i]=0;
        }
    }
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(int i=head[u];i;i=NEXT[i]){
            int y=ver[i];
            if(mark[i]) continue;
            if(dy[y]==-1){
                dy[y]=dx[u]+1;
                if(linky[y]==-1)
                    flag=true;
                else {
                    dx[linky[y]]=dy[y]+1;
                    q.push(linky[y]);
                }
            }
        }
    }
    return flag;
}
bool dfs(int x){
    for(int i=head[x];i;i=NEXT[i]){
        int y=ver[i];
        if(mark[i]) continue;
        if(dy[y]==dx[x]+1){
            dy[y]=0;
            if(linky[y]==-1||dfs(linky[y])){
                linky[y]=x;
                linkx[x]=y;
                return true;
            }
        }
    }
    return false;
}
void hk()
{
    int ans=0;
    while(bfs())
    {
        for(int i=0;i<=5000;i++)
        {
            if(linkx[i]==-1 && dfs(i))
                ans++;
        }
    }
    ans=0;
    for(int i=0;i<=5000;i++){
        if(linkx[i]==-1) break;
        ans++;
    }
    printf("%d\n",ans);
}
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int n,m;
    tot=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++){
        scanf("%d",&b[i]);
        num[b[i]][a[i]]++;
    }
    for(int i=1;i<=m;i++){
        for(int j=0;j<=5000;j++){
            if(num[i][j]) {
                link(j,i+5000);
                bian[i][j]=tot;
            }
        }
    }
    int q,inp;
    scanf("%d",&q);
    while(q--){
        scanf("%d",&inp);
        num[b[inp]][a[inp]]--;
        if(num[b[inp]][a[inp]]==0){
            int tmp=bian[b[inp]][a[inp]];
            //cout<<tmp<<endl;
            mark[tmp]=true;
        }
        memset(linkx,-1,sizeof(linkx));
        memset(linky,-1,sizeof(linky));
        hk();
    }
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=1e5+7,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}
int match[N],a[N],b[N],num[N],ans[N];
bool vis[N],Vis[N];
bool dfs(int x){
    for(int i=head[x];i;i=NEXT[i]){
        int y=ver[i];
        if(vis[y]) continue;
        vis[y]=true;
        if(match[y]==-1||dfs(match[y])){
            match[y]=x;
            return true;
        }
    }
    return false;
}
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++){
        scanf("%d",&b[i]);
    }
    int q;
    scanf("%d",&q);
    for(int i=1;i<=q;i++){
        scanf("%d",&num[i]);
        Vis[num[i]]=true;
    }
    for(int i=1;i<=n;i++){
        if(Vis[i]) continue;
        link(a[i],b[i]+5000);
    }
    int res=0;
    memset(match,-1,sizeof(match));
    for(int i=q;i>=1;i--){
        //cout<<a[num[i]]<<' '<<b[num[i]]<<endl;
        for(int j=res;j<=5000;j++){
            memset(vis,false,sizeof(vis));
            if(dfs(j)) res++;
            else break;
        }
        ans[i]=res;
        link(a[num[i]],b[num[i]]+5000);
        //printf("%d\n",ans);
    }
    for(int i=1;i<=q;i++) printf("%d\n",ans[i]);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


#include <cstdio>
const int maxn = int(1e5) + 7;
int n, m, d, clk, link[maxn], val[maxn], group[maxn], query[maxn], ans[maxn], vis[maxn];
bool disabled[maxn];
struct { int next, v; } edge[maxn];
struct Graph {
    int head[maxn], cnt;
    void addedge(int u, int v) {
        edge[cnt] = {head[u], v};
        head[u] = cnt++;
    }
} graph;
void init() {
    for (int i = 0; i < maxn; i++) link[i] = graph.head[i] = -1;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", val + i);
    for (int i = 1; i <= n; i++) scanf("%d", group + i);
    scanf("%d", &d);
    for (int i = 1; i <= d; i++) scanf("%d", query + i), disabled[query[i]] = true;
    for (int i = 1; i <= n; i++) if (!disabled[i]) graph.addedge(val[i], group[i] + n);
}
bool dfs(int u) {
    for (int i = graph.head[u]; ~i; i = edge[i].next) {
        int v = edge[i].v;
        if (vis[v] == clk) continue;
        vis[v] = clk;
        if (link[v] == -1 || dfs(link[v])) {
            link[v] = u;
            return true;
        }
    }
    return false;
}
int calc(int l) {
    for (int i = l; i < maxn; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return i;
        }
    }
}
void solve() {
    for (int i = d; i >= 1; i--) {
        ans[i] = calc(ans[i + 1]);
        int idx = query[i];
        graph.addedge(val[idx], group[idx] + n);
    }
}
int main() {
    init();
    solve();
    for (int i = 1; i <= d; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <bits/stdc++.h>
const int maxn = int(1e5) + 7;
int n, m, d, clk, top, link[maxn], val[maxn], group[maxn], query[maxn], ans[maxn], vis[maxn], stack[maxn];
bool disabled[maxn];
std::vector<int> edge[maxn];
void init() {
    memset(link, 0xff, sizeof(link));
    std::cin >> n >> m;
    for (int i = 1; i <= n; i++) std::cin >> val[i];
    for (int i = 1; i <= n; i++) std::cin >> group[i];
    std::cin >> d;
    for (int i = 1; i <= d; i++) std::cin >> query[i], disabled[query[i]] = true;
    for (int i = 1; i <= n; i++) if (!disabled[i]) edge[val[i]].push_back(group[i] + n);
}
bool dfs(int u) {
    for (int v : edge[u]) {
        if (vis[v] == clk) continue;
        vis[v] = clk;
        if (link[v] == -1 || dfs(link[v])) {
            link[v] = u;
            stack[++top] = v;
            return true;
        }
    }
    return false;
}
bool check(int mid) {  // mex is mid
    while (top) link[stack[top--]] = -1;
    for (int i = 0; i < mid; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return false;
        }
    }
    return true;
}
int calc() {
    int l = 0, r = 5000, mid, ans = 0;
    while (l <= r) {
        mid = (l + r) >> 1;
        if (check(mid)) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    return ans;
}
void solve() {
    for (int i = d; i >= 1; i--) {
        ans[i] = calc();
        int idx = query[i];
        edge[val[idx]].push_back(group[idx] + n);
    }
}
int main() {
#ifdef __AC
    freopen("../in.txt", "r", stdin);
#endif
    init();
    solve();
    for (int i = 1; i <= d; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <cstdio>
const int maxn = int(1e5) + 7;
int n, m, d, clk, link[maxn], val[maxn], group[maxn], query[maxn], ans[maxn], vis[maxn];
bool disabled[maxn];
struct { int next, v; } edge[maxn];
struct Graph {
    int head[maxn], cnt;
    void addedge(int u, int v) {
        edge[cnt] = {head[u], v};
        head[u] = cnt++;
    }
} graph;
void init() {
    for (int i = 0; i < maxn; i++) link[i] = graph.head[i] = -1;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", val + i);
    for (int i = 1; i <= n; i++) scanf("%d", group + i);
    scanf("%d", &d);
    for (int i = 1; i <= d; i++) scanf("%d", query + i), disabled[query[i]] = true;
    for (int i = 1; i <= n; i++) if (!disabled[i]) graph.addedge(val[i], group[i] + n);
}
bool dfs(int u) {
    for (int i = graph.head[u]; ~i; i = edge[i].next) {
        int v = edge[i].v;
        if (vis[v] == clk) continue;
        vis[v] = clk;
        if (link[v] == -1 || dfs(link[v])) {
            link[v] = u;
            return true;
        }
    }
    return false;
}
int calc(int l) {
    for (int i = l; i < 6000; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return i;
        }
    }
}
int calc() {
    for (int i = 0; i < 6000; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return i;
        }
    }
    return true;
}
void solve() {
    ans[d] = calc();
    for (int i = d - 1; i >= 1; i--) {
        int idx = query[i + 1];
        graph.addedge(val[idx], group[idx] + n);
        ans[i] = calc(ans[i + 1]);
    }
}
int main() {
    init();
    solve();
    for (int i = 1; i <= d; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <cstdio>
const int maxn = int(1e4) + 7;
int n, m, d, clk, base, link[maxn], val[maxn], group[maxn], query[maxn], ans[maxn], vis[maxn];
bool disabled[maxn];
struct { int next, v; } edge[maxn];
struct Graph {
    int head[maxn], cnt;
    void addedge(int u, int v) {
        edge[cnt] = {head[u], v};
        head[u] = cnt++;
    }
} graph;
void init() {
    for (int i = 0; i < maxn; i++) link[i] = graph.head[i] = -1;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%d", val + i);
        if (val[i] > base) base = val[i];
    }
    for (int i = 1; i <= n; i++) scanf("%d", group + i);
    scanf("%d", &d);
    for (int i = 1; i <= d; i++) scanf("%d", query + i), disabled[query[i]] = true;
    for (int i = 1; i <= n; i++) if (!disabled[i]) graph.addedge(val[i], group[i] + base + 1);
}
bool dfs(int u) {
    for (int i = graph.head[u]; ~i; i = edge[i].next) {
        int v = edge[i].v;
        if (vis[v] == clk) continue;
        vis[v] = clk;
        if (link[v] == -1 || dfs(link[v])) {
            link[v] = u;
            return true;
        }
    }
    return false;
}
int calc(int l) {
    for (int i = l; i < maxn; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return i;
        }
    }
}
void solve() {
    for (int i = d; i >= 1; i--) {
        ans[i] = calc(ans[i + 1]);
        int idx = query[i];
        graph.addedge(val[idx], group[idx] + base + 1);
    }
}
int main() {
#ifdef __AC
    freopen("../in.txt", "r", stdin);
#endif
    init();
    solve();
    for (int i = 1; i <= d; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <bits/stdc++.h>
const int maxn = int(1e5) + 7;
int n, m, d, clk, link[maxn], val[maxn], group[maxn], query[maxn], ans[maxn], vis[maxn];
bool disabled[maxn];
struct { int next, v; } edge[maxn];
struct Graph {
    int head[maxn], cnt;
    Graph() { memset(head, 0xff, sizeof(head)), cnt = 0; }
    void addedge(int u, int v) {
        edge[cnt] = {head[u], v};
        head[u] = cnt++;
    }
} graph;
void init() {
    memset(link, 0xff, sizeof(link));
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", val + i);
    for (int i = 1; i <= n; i++) scanf("%d", group + i);
    scanf("%d", &d);
    for (int i = 1; i <= d; i++) scanf("%d", query + i), disabled[query[i]] = true;
    for (int i = 1; i <= n; i++) if (!disabled[i]) graph.addedge(val[i], group[i] + n);
}
bool dfs(int u) {
    for (int i = graph.head[u]; ~i; i = edge[i].next) {
        int v = edge[i].v;
        if (vis[v] == clk) continue;
        vis[v] = clk;
        if (link[v] == -1 || dfs(link[v])) {
            link[v] = u;
            return true;
        }
    }
    return false;
}
int calc(int l) {
    for (int i = l; i < 6000; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return i;
        }
    }
}
int calc() {
    for (int i = 0; i < 6000; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return i;
        }
    }
    return true;
}
void solve() {
    ans[d] = calc();
    for (int i = d - 1; i >= 1; i--) {
        int idx = query[i + 1];
        graph.addedge(val[idx], group[idx] + n);
        ans[i] = calc(ans[i + 1]);
    }
}
int main() {
#ifdef __AC
    freopen("../in.txt", "r", stdin);
#endif
    init();
    solve();
    for (int i = 1; i <= d; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <bits/stdc++.h>
const int maxn = int(1e5) + 7;
int n, m, d, link[maxn], val[maxn], group[maxn], query[maxn], ans[maxn], vis[maxn], clk;
bool disabled[maxn];
std::vector<int> edge[maxn];
void init() {
    std::cin >> n >> m;
    for (int i = 1; i <= n; i++) std::cin >> val[i];
    for (int i = 1; i <= n; i++) std::cin >> group[i];
    std::cin >> d;
    for (int i = 1; i <= d; i++) std::cin >> query[i], disabled[query[i]] = true;
    for (int i = 1; i <= n; i++) if (!disabled[i]) edge[val[i]].push_back(group[i] + n);
}
bool dfs(int u) {
    for (int v : edge[u]) {
        if (vis[v] == clk) continue;
        vis[v] = clk;
        if (link[v] == -1 || dfs(link[v])) {
            link[v] = u;
            return true;
        }
    }
    return false;
}
bool check(int mid) {  // mex is mid
    memset(link, 0xff, sizeof(link));
    for (int i = 0; i < mid; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return false;
        }
    }
    return true;
}
int calc() {
    int l = 0, r = 5000, mid, ans = 0;
    while (l <= r) {
        mid = (l + r) >> 1;
        if (check(mid)) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    return ans;
}
void solve() {
    for (int i = d; i >= 1; i--) {
        ans[i] = calc();
        int idx = query[i];
        edge[val[idx]].push_back(group[idx] + n);
    }
}
int main() {
    init();
    solve();
    for (int i = 1; i <= d; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <bits/stdc++.h>
const int maxn = int(1e5) + 7;
int n, m, d, clk, top, link[maxn], val[maxn], group[maxn], query[maxn], ans[maxn], vis[maxn], stack[maxn];
bool disabled[maxn];
struct { int next, v; } edge[maxn];
struct Graph {
    int head[maxn], cnt;
    Graph() { memset(head, 0xff, sizeof(head)), cnt = 0; }
    void addedge(int u, int v) {
        edge[cnt] = {head[u], v};
        head[u] = cnt++;
    }
} graph;
void init() {
    memset(link, 0xff, sizeof(link));
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", val + i);
    for (int i = 1; i <= n; i++) scanf("%d", group + i);
    scanf("%d", &d);
    for (int i = 1; i <= d; i++) scanf("%d", query + i), disabled[query[i]] = true;
    for (int i = 1; i <= n; i++) if (!disabled[i]) graph.addedge(val[i], group[i] + n);
}
bool dfs(int u) {
    for (int i = graph.head[u]; ~i; i = edge[i].next) {
        int v = edge[i].v;
        if (vis[v] == clk) continue;
        vis[v] = clk;
        if (link[v] == -1 || dfs(link[v])) {
            link[v] = u;
            stack[++top] = v;
            return true;
        }
    }
    return false;
}
bool check(int mid) {  // mex is mid
    while (top) link[stack[top--]] = -1;
    for (int i = 0; i < mid; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return false;
        }
    }
    return true;
}
int calc() {
    int l = 0, r = 5000, mid, ans = 0;
    while (l <= r) {
        mid = (l + r) >> 1;
        if (check(mid)) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    return ans;
}
void solve() {
    for (int i = d; i >= 1; i--) {
        ans[i] = calc();
        int idx = query[i];
        graph.addedge(val[idx], group[idx] + n);
    }
}
int main() {
#ifdef __AC
    freopen("../in.txt", "r", stdin);
#endif
    init();
    solve();
    for (int i = 1; i <= d; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <cstdio>
const int maxn = int(1e4) + 7;
int n, m, d, clk, base = 5000, link[maxn], val[maxn], group[maxn], query[maxn], ans[maxn], vis[maxn];
bool disabled[maxn];
struct { int next, v; } edge[maxn];
struct Graph {
    int head[maxn], cnt;
    void addedge(int u, int v) {
        edge[cnt] = {head[u], v};
        head[u] = cnt++;
    }
} graph;
void init() {
    for (int i = 0; i < maxn; i++) link[i] = graph.head[i] = -1;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", val + i);
    for (int i = 1; i <= n; i++) scanf("%d", group + i);
    scanf("%d", &d);
    for (int i = 1; i <= d; i++) scanf("%d", query + i), disabled[query[i]] = true;
    for (int i = 1; i <= n; i++) if (!disabled[i]) graph.addedge(val[i], group[i] + base);
}
bool dfs(int u) {
    for (int i = graph.head[u]; ~i; i = edge[i].next) {
        int v = edge[i].v;
        if (vis[v] == clk) continue;
        vis[v] = clk;
        if (link[v] == -1 || dfs(link[v])) {
            link[v] = u;
            return true;
        }
    }
    return false;
}
int calc(int l) {
    for (int i = l; i < maxn; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return i;
        }
    }
}
void solve() {
    for (int i = d; i >= 1; i--) {
        ans[i] = calc(ans[i + 1]);
        int idx = query[i];
        graph.addedge(val[idx], group[idx] + base);
    }
}
int main() {
#ifdef __AC
    freopen("../in.txt", "r", stdin);
#endif
    init();
    solve();
    for (int i = 1; i <= d; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <cstdio>
const int maxn = int(1e5) + 7;
int n, m, d, clk, base, link[maxn], val[maxn], group[maxn], query[maxn], ans[maxn], vis[maxn];
bool disabled[maxn];
struct { int next, v; } edge[maxn];
struct Graph {
    int head[maxn], cnt;
    void addedge(int u, int v) {
        edge[cnt] = {head[u], v};
        head[u] = cnt++;
    }
} graph;
void init() {
    for (int i = 0; i < maxn; i++) link[i] = graph.head[i] = -1;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%d", val + i);
        if (val[i] > base) base = val[i];
    }
    for (int i = 1; i <= n; i++) scanf("%d", group + i);
    scanf("%d", &d);
    for (int i = 1; i <= d; i++) scanf("%d", query + i), disabled[query[i]] = true;
    for (int i = 1; i <= n; i++) if (!disabled[i]) graph.addedge(val[i], group[i] + base + 1);
}
bool dfs(int u) {
    for (int i = graph.head[u]; ~i; i = edge[i].next) {
        int v = edge[i].v;
        if (vis[v] == clk) continue;
        vis[v] = clk;
        if (link[v] == -1 || dfs(link[v])) {
            link[v] = u;
            return true;
        }
    }
    return false;
}
int calc(int l) {
    for (int i = l; i < maxn; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return i;
        }
    }
}
void solve() {
    for (int i = d; i >= 1; i--) {
        ans[i] = calc(ans[i + 1]);
        int idx = query[i];
        graph.addedge(val[idx], group[idx] + base + 1);
    }
}
int main() {
#ifdef __AC
    freopen("../in.txt", "r", stdin);
#endif
    init();
    solve();
    for (int i = 1; i <= d; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <bits/stdc++.h>
const int maxn = int(1e5) + 7;
int n, m, d, clk, top, link[maxn], val[maxn], group[maxn], query[maxn], ans[maxn], vis[maxn], stack[maxn];
bool disabled[maxn];
std::vector<int> edge[maxn];
void init() {
    memset(link, 0xff, sizeof(link));
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", val + i);
    for (int i = 1; i <= n; i++) scanf("%d", group + i);
    scanf("%d", &d);
    for (int i = 1; i <= d; i++) scanf("%d", query + i), disabled[query[i]] = true;
    for (int i = 1; i <= n; i++) if (!disabled[i]) edge[val[i]].push_back(group[i] + n);
}
bool dfs(int u) {
    for (int v : edge[u]) {
        if (vis[v] == clk) continue;
        vis[v] = clk;
        if (link[v] == -1 || dfs(link[v])) {
            link[v] = u;
            stack[++top] = v;
            return true;
        }
    }
    return false;
}
bool check(int mid) {  // mex is mid
    while (top) link[stack[top--]] = -1;
    for (int i = 0; i < mid; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return false;
        }
    }
    return true;
}
int calc() {
    int l = 0, r = 5000, mid, ans = 0;
    while (l <= r) {
        mid = (l + r) >> 1;
        if (check(mid)) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    return ans;
}
void solve() {
    for (int i = d; i >= 1; i--) {
        ans[i] = calc();
        int idx = query[i];
        edge[val[idx]].push_back(group[idx] + n);
    }
}
int main() {
#ifdef __AC
    freopen("../in.txt", "r", stdin);
#endif
    init();
    solve();
    for (int i = 1; i <= d; i++) printf("%d\n", ans[i]);
    return 0;
}


#include <bits/stdc++.h>
const int maxn = int(5e3) + 7;
int n, m, d, clk, top, link[maxn << 1], val[maxn], group[maxn], query[maxn], ans[maxn], vis[maxn], stack[maxn];
bool disabled[maxn];
struct { int next, v; } edge[maxn];
struct Graph {
    int head[maxn], cnt;
    Graph() { memset(head, 0xff, sizeof(head)), cnt = 0; }
    void addedge(int u, int v) {
        edge[cnt] = {head[u], v};
        head[u] = cnt++;
    }
} graph;
void init() {
    memset(link, 0xff, sizeof(link));
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", val + i);
    for (int i = 1; i <= n; i++) scanf("%d", group + i);
    scanf("%d", &d);
    for (int i = 1; i <= d; i++) scanf("%d", query + i), disabled[query[i]] = true;
    for (int i = 1; i <= n; i++) if (!disabled[i]) graph.addedge(val[i], group[i] + n);
}
bool dfs(int u) {
    for (int i = graph.head[u]; ~i; i = edge[i].next) {
        int v = edge[i].v;
        if (vis[v] == clk) continue;
        vis[v] = clk;
        if (link[v] == -1 || dfs(link[v])) {
            link[v] = u;
            stack[++top] = v;
            return true;
        }
    }
    return false;
}
bool check(int mid) {  // mex is mid
    while (top) link[stack[top--]] = -1;
    for (int i = 0; i < mid; i++) {
        if (link[i] == -1) {
            clk++;
            if (!dfs(i)) return false;
        }
    }
    return true;
}
int calc() {
    int l = 0, r = 5000, mid, ans = 0;
    while (l <= r) {
        mid = (l + r) >> 1;
        if (check(mid)) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    return ans;
}
void solve() {
    for (int i = d; i >= 1; i--) {
        ans[i] = calc();
        int idx = query[i];
        graph.addedge(val[idx], group[idx] + n);
    }
}
int main() {
#ifdef __AC
    freopen("../in.txt", "r", stdin);
#endif
    init();
    solve();
    for (int i = 1; i <= d; i++) printf("%d\n", ans[i]);
    return 0;
}


/*
	  Author : @evenbao
	  Created : 2020 / 07 / 09
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin() , x.end()

const int N = 20000 + 10;

struct Edge {
		int to , nxt;
} E[N << 1];

int n , m , q , tot;
int val[N] , id[N] , c[N] , vis[N] , head[N] , match[N] , ban[N];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

inline void AddEdge(int u , int v) {
		E[++tot] = (Edge) {v , head[u]};
		head[u] = tot;
}
inline bool findpath(int u) {
		for (int i = head[u]; i; i = E[i].nxt) {
				int v = E[i].to;
				if (!vis[v]) {
						vis[v] = true;
						if (match[v] == -1 || findpath(match[v])) {
								match[v] = u;
								return true;
						}
				}
		}
		return false;
}

int main() {

		read(n); read(m);
		for (int i = 1; i <= n; ++i) read(val[i]);
		for (int i = 1; i <= n; ++i) read(c[i]);
		read(q);
		for (int i = 1; i <= q; ++i) {
				read(id[i]);
				ban[id[i]] = true;
		}
		for (int i = 1; i <= n; ++i)
				if (!ban[i] && val[i] <= m) AddEdge(val[i] , m + c[i]);
		int now = 0;
		memset(match , 255 , sizeof(match));
		memset(vis , false , sizeof(vis));
		while (findpath(now)) ++now;
		vector < int > ans; ans.clear();
		ans.emplace_back(now);
		for (int i = q; i > 1; --i) {
				if (val[id[i]] > m) {
						ans.emplace_back(now);
						continue;
				}
				AddEdge(val[id[i]] , m + c[id[i]]);
				memset(vis , false , sizeof(vis));
				while (findpath(now)) {
						memset(vis , false , sizeof(vis));
						++now;
				}
				ans.emplace_back(now);
		}
		reverse(all(ans));
		for (int x : ans)
				printf("%d\n" , x);
	  return 0;
}


/*
	  Author : @evenbao
	  Created : 2020 / 07 / 09
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin() , x.end()

const int N = 20000 + 10;

struct Edge {
		int to , nxt;
} E[N << 1];

int n , m , q , tot;
int val[N] , id[N] , c[N] , vis[N] , head[N] , match[N] , ban[N];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

inline void AddEdge(int u , int v) {
		E[++tot] = (Edge) {v , head[u]};
		head[u] = tot;
}
inline bool findpath(int u) {
		for (int i = head[u]; i; i = E[i].nxt) {
				int v = E[i].to;
				if (!vis[v]) {
						vis[v] = true;
						if (match[v] == -1 || findpath(match[v])) {
								match[v] = u;
								return true;
						}
				}
		}
		return false;
}

int main() {

		read(n); read(m);
		for (int i = 1; i <= n; ++i) read(val[i]);
		for (int i = 1; i <= n; ++i) read(c[i]);
		read(q);
		for (int i = 1; i <= q; ++i) {
				read(id[i]);
				ban[id[i]] = true;
		}
		for (int i = 1; i <= n; ++i)
				if (!ban[i] && val[i] <= m) AddEdge(val[i] , m + c[i]);
		int now = 0;
		memset(match , 255 , sizeof(match));
		memset(vis , false , sizeof(vis));
		while (findpath(now)) {
				memset(vis , false , sizeof(vis));
				++now;
		}
		vector < int > ans; ans.clear();
		ans.emplace_back(now);
		for (int i = q; i > 1; --i) {
				if (val[id[i]] > m) {
						ans.emplace_back(now);
						continue;
				}
				AddEdge(val[id[i]] , m + c[id[i]]);
				memset(vis , false , sizeof(vis));
				while (findpath(now)) {
						memset(vis , false , sizeof(vis));
						++now;
				}
				ans.emplace_back(now);
		}
		reverse(all(ans));
		for (int x : ans)
				printf("%d\n" , x);
	  return 0;
}


/*
	  Author : @evenbao
	  Created : 2020 / 07 / 09
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin() , x.end()

const int N = 20000 + 10;

struct Edge {
		int to , nxt;
} E[N << 1];

int n , m , q , tot;
int val[N] , id[N] , c[N] , vis[N] , head[N] , match[N] , ban[N];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

inline void AddEdge(int u , int v) {
		E[++tot] = (Edge) {v , head[u]};
		head[u] = tot;
}
inline bool findpath(int u) {
		for (int i = head[u]; i; i = E[i].nxt) {
				int v = E[i].to;
				if (!vis[v]) {
						vis[v] = true;
						if (match[v] == -1 || findpath(match[v])) {
								match[v] = u;
								return true;
						}
				}
		}
		return false;
}

int main() {

		read(n); read(m);
		for (int i = 1; i <= n; ++i) read(val[i]);
		for (int i = 1; i <= n; ++i) read(c[i]);
		read(q);
		for (int i = 1; i <= q; ++i) {
				read(id[i]);
				ban[id[i]] = true;
		}
		for (int i = 1; i <= n; ++i)
				if (!ban[i] && val[i] <= m) AddEdge(val[i] , m + c[i]);
		int now = 0;
		memset(match , 255 , sizeof(match));
		memset(vis , false , sizeof(vis));
		while (findpath(now)) ++now;
		vector < int > ans; ans.clear();
		ans.emplace_back(now);
		for (int i = q; i > 1; --i) {
				AddEdge(val[id[i]] , m + c[id[i]]);
				if (val[id[i]] > m) continue;
				memset(vis , false , sizeof(vis));
				while (findpath(now)) {
						memset(vis , false , sizeof(vis));
						++now;
				}
				ans.emplace_back(now);
		}
		reverse(all(ans));
		for (int x : ans)
				printf("%d\n" , x);
	  return 0;
}


/*
	  Author : @evenbao
	  Created : 2020 / 07 / 09
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin() , x.end()

const int N = 10000 + 10;

struct Edge {
		int to , nxt;
} E[N << 1];

int n , m , q , tot;
int val[N] , id[N] , c[N] , vis[N] , head[N] , match[N] , ban[N];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

inline void AddEdge(int u , int v) {
		E[++tot] = (Edge) {v , head[u]};
		head[u] = tot;
}
inline bool findpath(int u) {
		for (int i = head[u]; i; i = E[i].nxt) {
				int v = E[i].to;
				if (!vis[v]) {
						vis[v] = true;
						if (match[v] == -1 || findpath(match[v])) {
								match[v] = u;
								return true;
						}
				}
		}
		return false;
}

int main() {

		read(n); read(m);
		for (int i = 1; i <= n; ++i) read(val[i]);
		for (int i = 1; i <= n; ++i) read(c[i]);
		read(q);
		for (int i = 1; i <= q; ++i) {
				read(id[i]);
				ban[id[i]] = true;
		}
		for (int i = 1; i <= n; ++i)
				if (!ban[i]) AddEdge(val[i] , n + c[i]);
		int now = 0;
		memset(match , 255 , sizeof(match));
		memset(vis , false , sizeof(vis));
		while (findpath(now)) ++now;
		vector < int > ans(q);
		ans.emplace_back(now);
		for (int i = q; i > 1; --i) {
				AddEdge(val[id[i]] , n + c[id[i]]);
				memset(vis , false , sizeof(vis));
				while (findpath(now)) {
						memset(vis , false , sizeof(vis));
						++now;
				}
				ans.emplace_back(now);
		}
		reverse(all(ans));
		for (int x : ans)
				printf("%d\n" , x);
	  return 0;
}


/*
	  Author : @evenbao
	  Created : 2020 / 07 / 09
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin() , x.end()

const int N = 10000 + 10;

struct Edge {
		int to , nxt;
} E[N << 1];

int n , m , q , tot;
int val[N] , id[N] , c[N] , vis[N] , head[N] , match[N] , ban[N];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

inline void AddEdge(int u , int v) {
		E[++tot] = (Edge) {v , head[u]};
		head[u] = tot;
}
inline int findpath(int u) {
		for (int i = head[u]; i; i = E[i].nxt) {
				int v = E[i].to;
				if (!vis[v]) {
						vis[v] = true;
						if (!match[v] || findpath(match[v])) {
								match[v] = u;
								return true;
						}
				}
		}
		return false;
}

int main() {

		read(n); read(m);
		for (int i = 1; i <= n; ++i) read(val[i]);
		for (int i = 1; i <= n; ++i) read(c[i]);
		read(q);
		for (int i = 1; i <= q; ++i) {
				read(id[i]);
				ban[id[i]] = true;
		}
		for (int i = 1; i <= n; ++i)
				if (!ban[i]) AddEdge(val[i] , n + c[i]);
		int now = 0;
		memset(vis , false , sizeof(vis));
		while (findpath(now)) ++now;
		vector < int > ans;
		ans.emplace_back(now);
		for (int i = q; i > 1; --i) {
				AddEdge(val[id[i]] , n + c[id[i]]);
				memset(vis , false , sizeof(vis));
				while (findpath(now)) {
						memset(vis , false , sizeof(vis));
						++now;
				}
				ans.emplace_back(now);
		}
		reverse(all(ans));
		for (int x : ans)
				printf("%d\n" , x);
	  return 0;
}


/*
	  Author : @evenbao
	  Created : 2020 / 07 / 09
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin() , x.end()

const int N = 20000 + 10;

struct Edge {
		int to , nxt;
} E[N << 1];

int n , m , q , tot;
int val[N] , id[N] , c[N] , vis[N] , head[N] , match[N] , ban[N];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

inline void AddEdge(int u , int v) {
		E[++tot] = (Edge) {v , head[u]};
		head[u] = tot;
}
inline bool findpath(int u) {
		for (int i = head[u]; i; i = E[i].nxt) {
				int v = E[i].to;
				if (!vis[v]) {
						vis[v] = true;
						if (match[v] == -1 || findpath(match[v])) {
								match[v] = u;
								return true;
						}
				}
		}
		return false;
}

int main() {

		read(n); read(m);
		for (int i = 1; i <= n; ++i) read(val[i]);
		for (int i = 1; i <= n; ++i) read(c[i]);
		read(q);
		for (int i = 1; i <= q; ++i) {
				read(id[i]);
				ban[id[i]] = true;
		}
		for (int i = 1; i <= n; ++i)
				if (!ban[i] && val[i] <= m) AddEdge(val[i] , m + c[i]);
		int now = 0;
		memset(match , 255 , sizeof(match));
		memset(vis , false , sizeof(vis));
		while (findpath(now)) ++now;
		vector < int > ans; ans.clear();
		ans.emplace_back(now);
		for (int i = q; i > 1; --i) {
				if (val[id[i]] > m) continue;
				AddEdge(val[id[i]] , m + c[id[i]]);
				memset(vis , false , sizeof(vis));
				while (findpath(now)) {
						memset(vis , false , sizeof(vis));
						++now;
				}
				ans.emplace_back(now);
		}
		reverse(all(ans));
		for (int x : ans)
				printf("%d\n" , x);
	  return 0;
}


/*
	  Author : @evenbao
	  Created : 2020 / 07 / 09
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin() , x.end()

const int N = 10000 + 10;

struct Edge {
		int to , nxt;
} E[N << 1];

int n , m , q , tot;
int val[N] , id[N] , c[N] , vis[N] , head[N] , match[N] , ban[N];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

inline void AddEdge(int u , int v) {
		E[++tot] = (Edge) {v , head[u]};
		head[u] = tot;
}
inline int findpath(int u) {
		for (int i = head[u]; i; i = E[i].nxt) {
				int v = E[i].to;
				if (!vis[v]) {
						vis[v] = true;
						if (match[v] == -1 || findpath(match[v])) {
								match[v] = u;
								return true;
						}
				}
		}
		return false;
}

int main() {

		read(n); read(m);
		for (int i = 1; i <= n; ++i) read(val[i]);
		for (int i = 1; i <= n; ++i) read(c[i]);
		read(q);
		for (int i = 1; i <= q; ++i) {
				read(id[i]);
				ban[id[i]] = true;
		}
		for (int i = 1; i <= n; ++i)
				if (!ban[i]) AddEdge(val[i] , n + c[i]);
		int now = 0;
		memset(match , 255 , sizeof(match));
		memset(vis , false , sizeof(vis));
		while (findpath(now)) ++now;
		vector < int > ans;
		ans.emplace_back(now);
		for (int i = q; i > 1; --i) {
				AddEdge(val[id[i]] , n + c[id[i]]);
				memset(vis , false , sizeof(vis));
				while (findpath(now)) {
						memset(vis , false , sizeof(vis));
						++now;
				}
				ans.emplace_back(now);
		}
		reverse(all(ans));
		for (int x : ans)
				printf("%d\n" , x);
	  return 0;
}


/*
	  Author : @evenbao
	  Created : 2020 / 07 / 09
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin() , x.end()

const int N = 20000 + 10;

struct Edge {
		int to , nxt;
} E[N << 1];

int n , m , q , tot;
int val[N] , id[N] , c[N] , vis[N] , head[N] , match[N] , ban[N];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

inline void AddEdge(int u , int v) {
		E[++tot] = (Edge) {v , head[u]};
		head[u] = tot;
}
inline bool findpath(int u) {
		for (int i = head[u]; i; i = E[i].nxt) {
				int v = E[i].to;
				if (!vis[v]) {
						vis[v] = true;
						if (match[v] == -1 || findpath(match[v])) {
								match[v] = u;
								return true;
						}
				}
		}
		return false;
}

int main() {

		read(n); read(m);
		for (int i = 1; i <= n; ++i) read(val[i]);
		for (int i = 1; i <= n; ++i) read(c[i]);
		read(q);
		for (int i = 1; i <= q; ++i) {
				read(id[i]);
				ban[id[i]] = true;
		}
		for (int i = 1; i <= n; ++i)
				if (!ban[i]) AddEdge(val[i] , n + c[i]);
		int now = 0;
		memset(match , 255 , sizeof(match));
		memset(vis , false , sizeof(vis));
		while (findpath(now)) ++now;
		vector < int > ans;
		ans.emplace_back(now);
		for (int i = q; i > 1; --i) {
				AddEdge(val[id[i]] , n + c[id[i]]);
				memset(vis , false , sizeof(vis));
				while (findpath(now)) {
						memset(vis , false , sizeof(vis));
						++now;
				}
				ans.emplace_back(now);
		}
		reverse(all(ans));
		for (int x : ans)
				printf("%d\n" , x);
	  return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <iostream>
#include <ctime>
#include <bitset>
#define gc getchar()
#define ll long long
#define il inline
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repn(i, b, a) for (int i = b; i >= a; --i)
#define ite iterator
#define eps 1e-8

using namespace std;

const int N = 5005, mod = 998244353;

template<class o> il void qr(o &x) {
    x = 0; char c = gc; int f = 1;
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = gc;}
    while (c >= '0' && c <= '9') {x = x * 10 + (c ^ 48); c = gc;}
    x *= f;
}

template<class o> void qw(o x) {
    if(x / 10) qw(x / 10); putchar(x % 10 + 48);
}

template<class o> void pr1(o x) {
    if (x < 0) putchar('-'), x = -x;
    qw(x); putchar(' ');
}

template<class o> void pr2(o x) {
    if (x < 0) putchar('-'), x = -x;
    qw(x); puts("");
}

il int ksm(int a, int b = mod - 2) {
    int ans = 1;
    for (; b; b >>= 1, a = 1ll * a * a % mod)
        if (b & 1) ans = 1ll * ans * a % mod;
    return ans;
}

il int add(int a, int b) {return a += b, a >= mod ? a - mod : a;}
il int sub(int a, int b) {return a -= b, a < 0 ? a + mod : a;}

/* code */

vector<int> e[N];
int match[N], p[N], c[N], q[N], ans[N];
bool vis[N], v[N];

bool dfs(int x) {
	for (int y : e[x]) if (!v[y]) {
		v[y] = 1;
		if (match[y] == -1 || dfs(match[y])) {match[y] = x; return 1;}
	} return 0;
}

void solve() {
    int n, m; qr(n), qr(m);
    rep (i, 1, n) qr(p[i]);
	rep (i, 1, n) qr(c[i]);
	rep (i, 0, n) match[i] = -1;
	int d; qr(d);
	rep (i, 1, d) {
		qr(q[i]); vis[q[i]] = 1;
	}
	rep (i, 1, n) if (!vis[i]) e[p[i]].pb(c[i]);
	int j = 0;
	repn (i, d, 1) {
		while (j <= m && dfs(j)) {++j; memset(v, 0, sizeof(v));}
		ans[i] = j; e[p[q[i]]].pb(c[q[i]]);
	} rep (i, 1, d) pr2(ans[i]);
}

int main() {
    //int T; qr(T); while (T--) {
        solve();
    //}
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <iostream>
#include <ctime>
#include <bitset>
#define gc getchar()
#define ll long long
#define il inline
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repn(i, b, a) for (int i = b; i >= a; --i)
#define ite iterator
#define eps 1e-8

using namespace std;

const int N = 5005, mod = 998244353;

template<class o> il void qr(o &x) {
    x = 0; char c = gc; int f = 1;
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = gc;}
    while (c >= '0' && c <= '9') {x = x * 10 + (c ^ 48); c = gc;}
    x *= f;
}

template<class o> void qw(o x) {
    if(x / 10) qw(x / 10); putchar(x % 10 + 48);
}

template<class o> void pr1(o x) {
    if (x < 0) putchar('-'), x = -x;
    qw(x); putchar(' ');
}

template<class o> void pr2(o x) {
    if (x < 0) putchar('-'), x = -x;
    qw(x); puts("");
}

il int ksm(int a, int b = mod - 2) {
    int ans = 1;
    for (; b; b >>= 1, a = 1ll * a * a % mod)
        if (b & 1) ans = 1ll * ans * a % mod;
    return ans;
}

il int add(int a, int b) {return a += b, a >= mod ? a - mod : a;}
il int sub(int a, int b) {return a -= b, a < 0 ? a + mod : a;}

/* code */

vector<int> e[N];
int match[N], p[N], c[N], q[N], ans[N];
bool vis[N];

bool dfs(int x) {
	for (int y : e[x]) {
		if (!match[y] || dfs(match[y])) {match[y] = x; return 1;}
	} return 0;
}

void solve() {
    int n, m; qr(n), qr(m);
    rep (i, 1, n) qr(p[i]);
	rep (i, 1, n) qr(c[i]);
	int d; qr(d);
	rep (i, 1, d) {
		qr(q[i]); vis[q[i]] = 1;
	}
	rep (i, 1, n) if (!vis[i]) e[p[i]].pb(c[i]);
	int j = 0;
	repn (i, d, 1) {
		while (dfs(j)) ++j;
		ans[i] = j; e[p[q[i]]].pb(c[q[i]]);
	} rep (i, 1, d) pr2(ans[i]);
}

int main() {
    //int T; qr(T); while (T--) {
        solve();
    //}
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <iostream>
#include <ctime>
#include <bitset>
#define gc getchar()
#define ll long long
#define il inline
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repn(i, b, a) for (int i = b; i >= a; --i)
#define ite iterator
#define eps 1e-8

using namespace std;

const int N = 5005, mod = 998244353;

template<class o> il void qr(o &x) {
    x = 0; char c = gc; int f = 1;
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = gc;}
    while (c >= '0' && c <= '9') {x = x * 10 + (c ^ 48); c = gc;}
    x *= f;
}

template<class o> void qw(o x) {
    if(x / 10) qw(x / 10); putchar(x % 10 + 48);
}

template<class o> void pr1(o x) {
    if (x < 0) putchar('-'), x = -x;
    qw(x); putchar(' ');
}

template<class o> void pr2(o x) {
    if (x < 0) putchar('-'), x = -x;
    qw(x); puts("");
}

il int ksm(int a, int b = mod - 2) {
    int ans = 1;
    for (; b; b >>= 1, a = 1ll * a * a % mod)
        if (b & 1) ans = 1ll * ans * a % mod;
    return ans;
}

il int add(int a, int b) {return a += b, a >= mod ? a - mod : a;}
il int sub(int a, int b) {return a -= b, a < 0 ? a + mod : a;}

/* code */

vector<int> e[N];
int match[N], p[N], c[N], q[N], ans[N];
bool vis[N], v[N];

bool dfs(int x) {
	for (int y : e[x]) if (!v[y]) {
		v[y] = 1;
		if (match[y] == -1 || dfs(match[y])) {match[y] = x; return 1;}
	} return 0;
}

void solve() {
    int n, m; qr(n), qr(m);
    rep (i, 1, n) qr(p[i]);
	rep (i, 1, n) qr(c[i]);
	rep (i, 0, n) match[i] = -1;
	int d; qr(d);
	rep (i, 1, d) {
		qr(q[i]); vis[q[i]] = 1;
	}
	rep (i, 1, n) if (!vis[i]) e[p[i]].pb(c[i]);
	int j = 0;
	repn (i, d, 1) {
		memset(v, 0, sizeof v);
		while (j <= m + 1 && dfs(j)) {++j; memset(v, 0, sizeof v);}
		ans[i] = j; e[p[q[i]]].pb(c[q[i]]);
	} rep (i, 1, d) pr2(ans[i]);
}

int main() {
    //int T; qr(T); while (T--) {
        solve();
    //}
    return 0;
}