#include<bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fo(i,a,b) for(ll i=a;i<b;i++)
#define pi 3.1415926536
#define ld long double
int main()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    int a=0,in=0,f=0;
    fo(i,0,n)
    {
        if(str[i]=='A')
            a++;
        if(str[i]=='I')
            in++;
        if(str[i]=='F')
            f++;
    }
    if(f==0)
        cout<<"0";
    else{
    if(in!=0)
        cout<<in;
    else
        cout<<a;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fo(i,a,b) for(ll i=a;i<b;i++)
#define pi 3.1415926536
#define ld long double
int main()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    int a=0,in=0,f=0;
    fo(i,0,n)
    {
        if(str[i]=='A')
            a++;
        if(str[i]=='I')
            in++;
        if(str[i]=='F')
            f++;
    }
    if(in==1)
        cout<<"1";
    else if(in>1)
        cout<<"0";
    else
        cout<<a;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fo(i,a,b) for(ll i=a;i<b;i++)
#define pi 3.1415926536
#define ld long double
int main()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    int a=0,in=0,f=0;
    fo(i,0,n)
    {
        if(str[i]=='A')
            a++;
        if(str[i]=='I')
            in++;
        if(str[i]=='F')
            f++;
    }
    if(in!=0)
        cout<<in;
    else
        cout<<a;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int SIZE;
    cin>>SIZE;
    char arr[SIZE];
    for(int i=0;i<SIZE;i++)
    {
        cin>>arr[i];
    }
    int cntr=0;
    int k=0;
    for(int i=0;i<SIZE;i++)
    {

        if(arr[i]=='A')
        {
            cntr++;
        }
        if(arr[i]=='I')
        {
            k++;
        }
    }
   if(k==1){cout<<1;}
   else if(k>1){cout<<0;}
   else
   {
       cout<<cntr;
   }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int SIZE;
    cin>>SIZE;
    char arr[SIZE];
    for(int i=0;i<SIZE;i++)
    {
        cin>>arr[i];
    }
    int cntr=0;
    for(int i=0;i<SIZE;i++)
    {

        if(arr[i]=='A')
        {
            cntr++;
        }
    }
    cout<<cntr;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int SIZE;
    cin>>SIZE;
    char arr[SIZE];
    for(int i=0;i<SIZE;i++)
    {
        cin>>arr[i];
    }
    int cntr=0;
    int i=0;
    for(int i=0;i<SIZE;i++)
    {

        if(arr[i]=='A')
        {
            cntr++;
        }
        if(arr[i]=='I')
        {
            i++;
        }
    }
   if(i==1){cout<<i;}
   else if(i>1){cout<<0;}
   else
   {
       cout<<cntr;
   }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,n;string s;a=b=c=0;
    cin>>n>>s;
    for(int i(0);i<n;++i){
        if(s[i]=='I')c++;
        else if(s[i]=='A')b++;
        else a++;
    }
    if(c>1)cout <<0;
    else if(c==1 &&n>1)cout <<c;
    else cout <<b;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,n;string s;a=b=c=0;
    cin>>n>>s;
    for(int i(0);i<n;++i){
        if(s[i]=='I')c++;
        else if(s[i]=='A')b++;
        else a++;
    }
    if(c==1 &&n>1)cout <<c;
    else cout <<b;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,n;string s;
    cin>>n>>s;
    for(int i(0);i<n;++i){
        if(s[i]=='I')c++;
        else if(s[i]=='A')b++;
        else a++;
    }
    if(c)cout <<c;
    else cout <<b;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,n;string s;a=b=c=0;
    cin>>n>>s;
    for(int i(0);i<n;++i){
        if(s[i]=='I')c++;
        else if(s[i]=='A')b++;
        else a++;
    }
    if(c)cout <<c;
    else cout <<b;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,in=0,al=0;
    cin>>n;
    int x=n;
    while(n--){
        char a;
        cin>>a;
        if(a=='A')al++;
        else if(a=='I')in++;
    }if(in==1)cout<<"1\n";
    else if(in==0)cout<<al<<endl;
    else cout<<"0\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,in=0,al=0;
    cin>>n;
    while(n--){
        char a;
        cin>>a;
        if(a=='A')al++;
        else if(a=='I')in++;
    }if(in==1)cout<<1<<endl;
    else if(al>1) cout<<al<<endl;
    else cout<<0<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,in=0,al=0;
    cin>>n;
    while(n--){
        char a;
        cin>>a;
        if(a=='A')al++;
        else if(a=='I')in++;
    }if(in==1)cout<<1<<endl;
    else cout<<al<<endl;
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int a,i,c=0,x,y,z;
cin>>a;
char s[a];
for(i=0;i<a;i++)
{
    cin>>s[i];
    x=count(s,s+a,'A');
    y=count(s,s+a,'I');
    z=count(s,s+a,'F');
}if(y==1){cout<<"1";}
else if(y==0){cout<<x;}
else {cout<<"0";}

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,i,c=0,x,y,z;
cin>>a;
char s[200001];
for(i=0;i<a;i++)
{
    cin>>s[i];
    x=count(s,s+a,'A');
    y=count(s,s+a,'I');
    z=count(s,s+a,'F');
}if(y==1){cout<<"1";}
else if(y==0){cout<<x;}
else {cout<<"0";}

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,i,c=0,x,y,z;
cin>>a;
char s[200001];
 cin>>s;
    x=count(s,s+a,'A');
    y=count(s,s+a,'I');
    z=count(s,s+a,'F');
if(y==1){cout<<"1";}
else if(y==0){cout<<x;}
else {cout<<"0";}

}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,i,c=0;
cin>>a;
char s[a];
for(i=0;i<a;i++)
{
    cin>>s[i];
    if(s[i]=='A'){c++;}
    else {c==0;}
}
cout<<c;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,i,c=0,x,y,z;
cin>>a;
char s[200001];
    cin>>s;
    x=count(s,s+a,'A');
    y=count(s,s+a,'I');
    z=count(s,s+a,'F');
}if(y==1){cout<<"1";}
else if(y==0){cout<<x;}
else {cout<<"0";}

}


#include <bits/stdc++.h>

#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define rep(i,n,N) for(ll i=n;i<=N;i++)
#define rap(i,n,N) for(int i=(int)n;i>=(int)N;i--)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define endl "\n"
const int MAX=1e5+5;
const ll MAX2 = 11;
const int MOD=1000000000 + 7;
const ll INF=20000;
const int dr[]={1,0,-1,0,1,1,-1,-1};
const int dc[]={0,1,0,-1,1,-1,1,-1};
const double pi = acos(-1);

int n,a,b,x,y,k,sz,cnt,res,tmp;
string s,t;
char c;

int main(){
//	cout<<fixed<<setprecision(10);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    while(n--){
    	cin>>c;
    	if(c=='A')a++;
    	else if(c=='I')b++;
    	else x++;
	}
	if(b&&x)cout<<b;
	else if(!b)cout<<a;
	else cout<<0;
    return 0;
}


#include <bits/stdc++.h>

#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define rep(i,n,N) for(ll i=n;i<=N;i++)
#define rap(i,n,N) for(int i=(int)n;i>=(int)N;i--)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define endl "\n"
const int MAX=1e5+5;
const ll MAX2 = 11;
const int MOD=1000000000 + 7;
const ll INF=20000;
const int dr[]={1,0,-1,0,1,1,-1,-1};
const int dc[]={0,1,0,-1,1,-1,1,-1};
const double pi = acos(-1);

int n,a,b,x,y,k,sz,cnt,res,tmp;
string s,t;
char c;

int main(){
//	cout<<fixed<<setprecision(10);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    while(n--){
    	cin>>c;
    	if(c=='A')a++;
    	else if(c=='I')b++;
    	else x++;
	}
	if(!b)cout<<a;
	else if(b==1)cout<<1;
	else cout<<0;
    return 0;
}


#include <bits/stdc++.h>

#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define rep(i,n,N) for(ll i=n;i<=N;i++)
#define rap(i,n,N) for(int i=(int)n;i>=(int)N;i--)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define endl "\n"
const int MAX=1e5+5;
const ll MAX2 = 11;
const int MOD=1000000000 + 7;
const ll INF=20000;
const int dr[]={1,0,-1,0,1,1,-1,-1};
const int dc[]={0,1,0,-1,1,-1,1,-1};
const double pi = acos(-1);

int n,a,b,x,y,k,sz,cnt,res,tmp;
string s,t;
char c;

int main(){
//	cout<<fixed<<setprecision(10);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    while(n--){
    	cin>>c;
    	if(c=='A')a++;
    	else if(c=='I')b++;
    	else x++;
	}
	if(b&&x)cout<<b;
	else cout<<a;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int maxN=(10005);
vector<int> v[maxN];
int l[maxN],r[maxN];
bool seen[maxN];

inline int path(int nod)
{
    if(seen[nod]) return 0;
    seen[nod]=1;
    for(auto it:v[nod])
    {
        if(!r[it])
        {
            r[it]=nod;
            l[nod]=it;
            return 1;
        }
    }

    for(auto it:v[nod])
    {
        if(path(r[it]))
        {
            r[it]=nod;
            l[nod]=it;
            return 1;
        }
    }

    seen[nod]=0;
    return 0;
}
const int offset=5000;
int p[maxN],c[maxN],q,x,qry[maxN];
bool del[maxN];
int ans[maxN];

int main()
{
    int n,m;
    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",&q);
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&x);
        qry[i]=x;
        del[x]=1;
    }

    for(int i=1;i<=n;i++)
        if(!del[i]) v[p[i]].push_back(offset+c[i]);

    for(int i=q;i;i--)
    {
        int j=ans[i+1]; //the last one that we couldn't match
        ans[i]=j;
      //  memset(seen,0,sizeof(seen));
        for(;j<5000;j++)
        {
            if(l[j])
            {
                 ans[i]=j+1;
                continue;

            }

            int augment=path(j);
            if(augment) ans[i]=j+1;
                else break;
        }

        v[p[qry[i]]].push_back(c[qry[i]]);

    }

    for(int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
    printf("\n");

    return 0;
}


// CF1139E Maximize Mex
// 和连续攻击一样
#include <bits/stdc++.h>
const int maxn = 5e3 + 5;
struct edge {
    int to, next;
} e[maxn];
int head[maxn], cnt;
int match[maxn];
void addedge(int u, int v) {
    e[++cnt] = {v, head[u]}; head[u] = cnt;
}
int Dfn[maxn];
int p[maxn], c[maxn], k[maxn];
bool flag[maxn];
int n, m;
bool dfs(int u, int dfn) {
    // assert(u != -1);
    for (int i = head[u]; i; i = e[i].next) {
        int v = e[i].to;
        if (dfn != Dfn[v]) {
            Dfn[v] = dfn;
            if (match[v] == -1 || dfs(match[v], dfn)) {
                match[v] = u;
                return 1;
            }
        }
    }
    return 0;
}
int ans[maxn];
int main() {
    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);
    int d; scanf("%d", &d);
    for (int i = 1;i <= d;++i) {
        scanf("%d", k + i);
        flag[k[i]] = 1;
    }
    for (int i = 1;i <= n;++i) {
        if (!flag[i]) {
            if (p[i] > m)   continue;
            // 双向边 vs 单向？
            addedge(p[i], c[i] + m), addedge(c[i] + m, p[i]);
        }
    }
    memset(match, -1, sizeof match);
    int now = 0, dd = 0;
    for (int i = d; i; --i) {
        ++dd;
        while(dfs(now, dd))   ++now, ++dd;
        ans[i] = now;
        if (p[k[i]] > m)    continue;
        addedge(p[k[i]], c[k[i]] + m), addedge(c[k[i]] + m, p[k[i]]);
    }
    for (int i = 1;i <= d;++i)  printf("%d\n", ans[i]);
    return 0;
}


// CF1139E Maximize Mex
// 和连续攻击一样
#include <bits/stdc++.h>
const int maxn = 1e6 + 5;
struct edge {
    int to, next;
} e[maxn];
int head[maxn], cnt;
int match[maxn];
void addedge(int u, int v) {
    e[++cnt] = {v, head[u]}; head[u] = cnt;
}
int Dfn[maxn];
int p[maxn], c[maxn], k[maxn];
bool flag[maxn];
int n, m;
bool dfs(int u, int dfn) {
    // assert(u != -1);
    for (int i = head[u]; i; i = e[i].next) {
        int v = e[i].to;
        if (dfn != Dfn[v]) {
            Dfn[v] = dfn;
            if (match[v] == -1 || dfs(match[v], dfn)) {
                match[v] = u;
                return 1;
            }
        }
    }
    return 0;
}
int ans[maxn];
int main() {
    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);
    int d; scanf("%d", &d);
    for (int i = 1;i <= d;++i) {
        scanf("%d", k + i);
        flag[k[i]] = 1;
    }
    for (int i = 1;i <= n;++i) {
        if (!flag[i]) {
            if (p[i] > m)   continue;
            // 双向边 vs 单向？
            addedge(p[i], c[i] + m), addedge(c[i] + m, p[i]);
        }
    }
    memset(match, -1, sizeof match);
    int now = 0, dd = 0;
    for (int i = d; i; --i) {
        ++dd;
        while(dfs(now, dd))   ++now, ++dd;
        ans[i] = now;
        if (p[k[i]] > m)    continue;
        addedge(p[k[i]], c[k[i]] + m), addedge(c[k[i]] + m, p[k[i]]);
    }
    for (int i = 1;i <= d;++i)  printf("%d\n", ans[i]);
    return 0;
}


// CF1139E Maximize Mex
// 和连续攻击一样
#include <bits/stdc++.h>
const int maxn = 5e4 + 5;
struct edge {
    int to, next;
} e[maxn];
int head[maxn], cnt;
int match[maxn];
void addedge(int u, int v) {
    e[++cnt] = {v, head[u]}; head[u] = cnt;
}
int Dfn[maxn];
int p[maxn], c[maxn], k[maxn];
bool flag[maxn];
int n, m;
bool dfs(int u, int dfn) {
    // assert(u != -1);
    for (int i = head[u]; i; i = e[i].next) {
        int v = e[i].to;
        if (dfn != Dfn[v]) {
            Dfn[v] = dfn;
            if (match[v] == -1 || dfs(match[v], dfn)) {
                match[v] = u;
                return 1;
            }
        }
    }
    return 0;
}
int ans[maxn];
int main() {
    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);
    int d; scanf("%d", &d);
    for (int i = 1;i <= d;++i) {
        scanf("%d", k + i);
        flag[k[i]] = 1;
    }
    for (int i = 1;i <= n;++i) {
        if (!flag[i]) {
            if (p[i] > m)   continue;
            // 双向边 vs 单向？
            addedge(p[i], c[i] + m), addedge(c[i] + m, p[i]);
        }
    }
    memset(match, -1, sizeof match);
    int now = 0, dd = 1;
    for (int i = d; i; --i) {
        while(dfs(now, dd))   ++now, ++dd;
        ans[i] = now;
        if (p[k[i]] > m)    continue;
        addedge(p[k[i]], c[k[i]] + m);
    }
    for (int i = 1;i <= n;++i)  printf("%d\n", ans[i]);
    return 0;
}


   #include <bits/stdc++.h>

//    #include <boost/multiprecision/cpp_int.hpp>
 #define int long long
 #define inf  1000000007
 #define pa pair<int,int>
 #define ll long long
 #define pal pair<double,double>
 #define ppap pair<pa,int>
  #define PI 3.14159265358979323846
  #define paa pair<int,char>
  #define  mp make_pair
  #define  pb push_back
  #define EPS (1e-10)

    int dx[8]={0,1,0,-1,1,1,-1,-1};
    int dy[8]={1,0,-1,0,-1,1,1,-1};
                                            using namespace std;
                                   			class pa3{
                                            	public:
                                            	int x;
                                   				int y,z;
                                            	pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
                                            	bool operator < (const pa3 &p) const{
                                            		if(x!=p.x) return x<p.x;
                                            		if(y!=p.y) return y<p.y;
                                            		 return z<p.z;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                   				bool operator > (const pa3 &p) const{
                                            		if(x!=p.x) return x>p.x;
                                            		if(y!=p.y) return y>p.y;
                                            		 return z>p.z;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa3 &p) const{
                                            		return x==p.x && y==p.y && z==p.z;
                                            	}
                                            		bool operator != (const pa3 &p) const{
                                            			return !( x==p.x && y==p.y && z==p.z);
                                            	}

                                            };

                                            class pa4{
                                            	public:
                                            	int x;
                                            	int y,z,w;
                                            	pa4(int x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
                                            	bool operator < (const pa4 &p) const{
                                            		if(x!=p.x) return x<p.x;
                                            		if(y!=p.y) return y<p.y;
                                            		if(z!=p.z)return z<p.z;
                                            		return w<p.w;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator > (const pa4 &p) const{
                                            		if(x!=p.x) return x>p.x;
                                            		if(y!=p.y) return y>p.y;
                                            		if(z!=p.z)return z>p.z;
                                            		return w>p.w;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa4 &p) const{
                                            		return x==p.x && y==p.y && z==p.z &&w==p.w;
                                            	}

                                            };
                                            class pa2{
                                            	public:
                                            	int x,y;
                                            	pa2(int x=0,int y=0):x(x),y(y) {}
                                            	pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
                                            	pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
                                            	bool operator < (const pa2 &p) const{
                                            		return y != p.y ? y<p.y: x<p.x;
                                            	}
                                            	bool operator > (const pa2 &p) const{
                                            		return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa2 &p) const{
                                            		return abs(x-p.x)==0 && abs(y-p.y)==0;
                                            	}
                                            	bool operator != (const pa2 &p) const{
                                            		return !(abs(x-p.x)==0 && abs(y-p.y)==0);
                                            	}

                                            };

                                string itos( int i ) {
                                ostringstream s ;
                                s << i ;
                                return s.str() ;
                                }

                                int gcd(int v,int b){
                                	if(v>b) return gcd(b,v);
                                	if(v==b) return b;
                                	if(b%v==0) return v;
                                	return gcd(v,b%v);
                                }

                                int mod;
int extgcd(int a, int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int d = extgcd(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
pa operator+(const pa & l,const pa & r) {
    return {l.first+r.first,l.second+r.second};
}
pa operator-(const pa & l,const pa & r) {
    return {l.first-r.first,l.second-r.second};
}

                int pr[200010];
                int inv[200010];

                int beki(int wa,int rr,int warukazu){
                	if(rr==0) return 1%warukazu;
                	if(rr==1) return wa%warukazu;
                	wa%=warukazu;
                	if(rr%2==1) return ((ll)beki(wa,rr-1,warukazu)*(ll)wa)%warukazu;
                	ll zx=beki(wa,rr/2,warukazu);
                	return (zx*zx)%warukazu;
                }

    			int comb(int nn,int rr){
    				if(rr<0 || rr>nn || nn<0) return 0;
    				int r=pr[nn]*inv[rr];
    				r%=mod;
    				r*=inv[nn-rr];
    				r%=mod;
    				return r;
    			}

                void gya(int ert){
                	pr[0]=1;
                	for(int i=1;i<=ert;i++){
                		pr[i]=(pr[i-1]*i)%mod;
                	}
                		inv[ert]=beki(pr[ert],mod-2,mod);
                	for(int i=ert-1;i>=0;i--){
                		inv[i]=inv[i+1]*(i+1)%mod;
                	}
                }

              //   cin.tie(0);
    		//	ios::sync_with_stdio(false);
    			//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
                 //sort(ve.begin(),ve.end(),greater<int>());
//    mt19937(clock_per_sec);
  //  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ;

                               //----------------kokomade tenpure------------

int p[5010],c[5001];
int use_q[5010]={};
vector<int> atode[5030];
int con=5010;

vector<pa> G[103030];

bool col[6000]={};

int vis[11010];
int mae[11000];

int x[6020],y[6020];

bool add(int b,int s,int t,int num){
	G[s].pb(mp(t+con,num));
	G[t+con].pb(mp(s,num));

	queue<pa> que;
	for(auto v:G[b])que.push(v);
//	que.push(mp(s,num));

	while(que.size()){
		pa z=que.front();
		que.pop();
		if(vis[z.first]==num) continue;
		vis[z.first]=num;
		mae[z.first]=z.second;

		if(z.first>=con){
			bool bo=false;
			for(auto v:G[z.first]){
		//		cout<<z.first-con<<" "<<v.second<<" "<<col[v.second]<<endl;
				if(col[v.second]){
					bo=1;
					if(vis[v.first]<num){
						que.push(v);
					}

				}
			}
				if(!bo){
					//

					int ima=z.first;
					while(1){
		//				cout<<ima<<" ";
				//		cout<<ima<<" "<<mae[ima]<<endl;
						if(ima==b) break;
						col[mae[ima]]^=1;
				//		cout<<x[mae[ima]]<<" "<<y[mae[ima]]<<" "<<ima<<endl;
						ima=(x[mae[ima]]^y[mae[ima]]^ima);
					}
		//			cout<<endl;
					/*
					for(int r=0;r<3;r++)cout<<col[r];
					cout<<endl;
					*/
					return 1;
				}

		}
		else{
			for(auto v:G[z.first]){
				if(col[v.second]==0){

					if(vis[v.first]<num){
						que.push(v);
					}
				}
			}
		}
	}
	return 0;
}

 signed main(){

    	       cin.tie(0);
   		ios::sync_with_stdio(false);
int n,m;
 	cin>>n>>m;
 	for(int i=0;i<11000;i++)vis[i]=-1;
 	for(int i=0;i<n;i++)cin>>p[i];
 	for(int i=0;i<n;i++){
 		cin>>c[i];
 		c[i]--;
 	}
	vector<int> que;
 	int q;
 	cin>>q;
 	for(int i=0;i<q;i++){
 		int y;
 		cin>>y;
 		y--;
 		use_q[y]=1;
 		que.pb(y);
 	}
 	for(int i=0;i<n;i++)if(!use_q[i])que.pb(i);
 	reverse(que.begin(),que.end());

 	vector<int> ans;
 	ans.pb(0);
 	int ima=0;
 	int cnt=0;
 	for(auto v:que){

 		//p[v] -> c[v]
// 		cout<<p[v]<<" "<<c[v]<<endl;
 		if(p[v]<ima){
 				x[cnt]=p[v];
 				y[cnt]=con+c[v];
 				bool f=add(ima,p[v],c[v],cnt);

 				cnt++;

 				if(!f){
 					ans.pb(ima);
 					continue;
 				}
 			ima++;
			 c[v]+=con;
 		}

 		else if(p[v]>=ima){
 		c[v]+=con;
 			atode[p[v]].pb(c[v]);
 		}
 		while(1){
 			int g=ima;
 			bool f=false;
 			while(atode[g].size()){
 	//			cout<<g<<"   "<<atode[g].back()<<endl;
 				if(f){
  					G[g].pb({atode[g].back(),cnt});
 					G[atode[g].back()].pb({g,cnt});
 					x[cnt]=g;
 					y[cnt]=atode[g].back();
 					cnt++;
 					atode[g].pop_back();
 					continue;
 				}
 				 x[cnt]=g;
 				y[cnt]=atode[g].back();
 				f=add(ima,g,atode[g].back()-con,cnt);
 				cnt++;
 				atode[g].pop_back();

 			}
 			if(f){
 				ima++;
 				continue;
 			}
 			break;
 		}
 		ans.pb(ima);
 	}
 	ans.pop_back();
 	reverse(ans.begin(),ans.end());
 	for(int i=0;i<q;i++)cout<<ans[i]<<endl;

 }


   #include <bits/stdc++.h>

//    #include <boost/multiprecision/cpp_int.hpp>
 #define int long long
 #define inf  1000000007
 #define pa pair<int,int>
 #define ll long long
 #define pal pair<double,double>
 #define ppap pair<pa,int>
  #define PI 3.14159265358979323846
  #define paa pair<int,char>
  #define  mp make_pair
  #define  pb push_back
  #define EPS (1e-10)

    int dx[8]={0,1,0,-1,1,1,-1,-1};
    int dy[8]={1,0,-1,0,-1,1,1,-1};
                                            using namespace std;
                                   			class pa3{
                                            	public:
                                            	int x;
                                   				int y,z;
                                            	pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
                                            	bool operator < (const pa3 &p) const{
                                            		if(x!=p.x) return x<p.x;
                                            		if(y!=p.y) return y<p.y;
                                            		 return z<p.z;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                   				bool operator > (const pa3 &p) const{
                                            		if(x!=p.x) return x>p.x;
                                            		if(y!=p.y) return y>p.y;
                                            		 return z>p.z;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa3 &p) const{
                                            		return x==p.x && y==p.y && z==p.z;
                                            	}
                                            		bool operator != (const pa3 &p) const{
                                            			return !( x==p.x && y==p.y && z==p.z);
                                            	}

                                            };

                                            class pa4{
                                            	public:
                                            	int x;
                                            	int y,z,w;
                                            	pa4(int x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
                                            	bool operator < (const pa4 &p) const{
                                            		if(x!=p.x) return x<p.x;
                                            		if(y!=p.y) return y<p.y;
                                            		if(z!=p.z)return z<p.z;
                                            		return w<p.w;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator > (const pa4 &p) const{
                                            		if(x!=p.x) return x>p.x;
                                            		if(y!=p.y) return y>p.y;
                                            		if(z!=p.z)return z>p.z;
                                            		return w>p.w;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa4 &p) const{
                                            		return x==p.x && y==p.y && z==p.z &&w==p.w;
                                            	}

                                            };
                                            class pa2{
                                            	public:
                                            	int x,y;
                                            	pa2(int x=0,int y=0):x(x),y(y) {}
                                            	pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
                                            	pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
                                            	bool operator < (const pa2 &p) const{
                                            		return y != p.y ? y<p.y: x<p.x;
                                            	}
                                            	bool operator > (const pa2 &p) const{
                                            		return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa2 &p) const{
                                            		return abs(x-p.x)==0 && abs(y-p.y)==0;
                                            	}
                                            	bool operator != (const pa2 &p) const{
                                            		return !(abs(x-p.x)==0 && abs(y-p.y)==0);
                                            	}

                                            };

                                string itos( int i ) {
                                ostringstream s ;
                                s << i ;
                                return s.str() ;
                                }

                                int gcd(int v,int b){
                                	if(v>b) return gcd(b,v);
                                	if(v==b) return b;
                                	if(b%v==0) return v;
                                	return gcd(v,b%v);
                                }

                                int mod;
int extgcd(int a, int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int d = extgcd(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
pa operator+(const pa & l,const pa & r) {
    return {l.first+r.first,l.second+r.second};
}
pa operator-(const pa & l,const pa & r) {
    return {l.first-r.first,l.second-r.second};
}

                int pr[200010];
                int inv[200010];

                int beki(int wa,int rr,int warukazu){
                	if(rr==0) return 1%warukazu;
                	if(rr==1) return wa%warukazu;
                	wa%=warukazu;
                	if(rr%2==1) return ((ll)beki(wa,rr-1,warukazu)*(ll)wa)%warukazu;
                	ll zx=beki(wa,rr/2,warukazu);
                	return (zx*zx)%warukazu;
                }

    			int comb(int nn,int rr){
    				if(rr<0 || rr>nn || nn<0) return 0;
    				int r=pr[nn]*inv[rr];
    				r%=mod;
    				r*=inv[nn-rr];
    				r%=mod;
    				return r;
    			}

                void gya(int ert){
                	pr[0]=1;
                	for(int i=1;i<=ert;i++){
                		pr[i]=(pr[i-1]*i)%mod;
                	}
                		inv[ert]=beki(pr[ert],mod-2,mod);
                	for(int i=ert-1;i>=0;i--){
                		inv[i]=inv[i+1]*(i+1)%mod;
                	}
                }

              //   cin.tie(0);
    		//	ios::sync_with_stdio(false);
    			//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
                 //sort(ve.begin(),ve.end(),greater<int>());
//    mt19937(clock_per_sec);
  //  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ;

                               //----------------kokomade tenpure------------

int p[5010],c[5001];
int use_q[5010]={};
vector<int> atode[5030];
int con=5010;

vector<pa> G[103030];

bool col[6000]={};

int vis[11010];
int mae[11000];

int x[6020],y[6020];

bool add(int b,int s,int t,int num){
	G[s].pb(mp(t+con,num));
	G[t+con].pb(mp(s,num));

	queue<pa> que;
	for(auto v:G[b])que.push(v);
//	que.push(mp(s,num));
//cout<<s<<" "<<t<<endl;
	while(que.size()){
		pa z=que.front();
		que.pop();
		if(vis[z.first]==num) continue;
		vis[z.first]=num;
		mae[z.first]=z.second;

		if(z.first>=con){
			bool bo=false;
			for(auto v:G[z.first]){
				if(col[v.second]){
					bo=1;
					if(vis[v.first]<num){
						que.push(v);
					}
				}
				if(!bo){
					//

					int ima=z.first;
					while(1){
				//		cout<<ima<<" "<<mae[ima]<<endl;
						if(ima==s) break;
						col[mae[ima]]^=1;
				//		cout<<x[mae[ima]]<<" "<<y[mae[ima]]<<" "<<ima<<endl;
						ima=(x[mae[ima]]^y[mae[ima]]^ima);
					}

					/*
					for(int r=0;r<3;r++)cout<<col[r];
					cout<<endl;
					*/
					return 1;
				}
			}

		}
		else{
			for(auto v:G[z.first]){
				if(col[v.second]==0){

					if(vis[v.first]<num){
						que.push(v);
					}
				}
			}
		}
	}
	return 0;
}

 signed main(){

    	       cin.tie(0);
   		ios::sync_with_stdio(false);
int n,m;
 	cin>>n>>m;
 	for(int i=0;i<11000;i++)vis[i]=-1;
 	for(int i=0;i<n;i++)cin>>p[i];
 	for(int i=0;i<n;i++){
 		cin>>c[i];
 		c[i]--;
 	}
	vector<int> que;
 	int q;
 	cin>>q;
 	for(int i=0;i<q;i++){
 		int y;
 		cin>>y;
 		y--;
 		use_q[y]=1;
 		que.pb(y);
 	}
 	for(int i=0;i<n;i++)if(!use_q[i])que.pb(i);
 	reverse(que.begin(),que.end());

 	vector<int> ans;
 	ans.pb(0);
 	int ima=0;
 	int cnt=0;
 	for(auto v:que){

 		//p[v] -> c[v]
// 		cout<<p[v]<<" "<<c[v]<<endl;
 		if(p[v]<ima){
 				x[cnt]=p[v];
 				y[cnt]=con+c[v];
 		//	G[p[v]].pb({con+c[v],cnt});
 		//		G[con+c[v]].pb({p[v],cnt});
 			bool	f=add(ima,p[v],c[v],cnt);

 			cnt++;

 			if(!f){
 			ans.pb(ima);
 				continue;
 			}
 			ima++;
 	//		cout<<ima<<" "<<p[v]<<" "<<c[v]<<endl;
 	//		cout<<"ha??"<<endl;
 c[v]+=con;
 		}

 		else if(p[v]>=ima){
 		c[v]+=con;
 			atode[p[v]].pb(c[v]);
 		}
 		while(1){
 			int g=ima;
 			bool f=false;
 			while(atode[g].size()){
 	//			cout<<g<<"   "<<atode[g].back()<<endl;
 				if(f){
  					G[g].pb({atode[g].back(),cnt});
 					G[atode[g].back()].pb({g,cnt});
 					x[cnt]=g;
 					y[cnt]=atode[g].back();
 					cnt++;
 					atode[g].pop_back();
 				}
 				 x[cnt]=g;
 				y[cnt]=atode[g].back();
 				f=add(ima,g,atode[g].back()-con,cnt);
/*
 				cout<<"==="<<endl;
	for(int i=0;i<10;i++)for(auto v:G[i]){
		cout<<i<<" "<<v.first-con<<" "<<v.second<<" "<<col[v.second]<<endl;
	}
 */
 				cnt++;
 				atode[g].pop_back();

 			}
 			if(f){
 				ima++;
 				continue;
 			}
 			break;
 		}
 		ans.pb(ima);
 	}
 	ans.pop_back();
 	reverse(ans.begin(),ans.end());
 	for(int i=0;i<q;i++)cout<<ans[i]<<endl;

 }


   #include <bits/stdc++.h>

//    #include <boost/multiprecision/cpp_int.hpp>
 #define int long long
 #define inf  1000000007
 #define pa pair<int,int>
 #define ll long long
 #define pal pair<double,double>
 #define ppap pair<pa,int>
  #define PI 3.14159265358979323846
  #define paa pair<int,char>
  #define  mp make_pair
  #define  pb push_back
  #define EPS (1e-10)

    int dx[8]={0,1,0,-1,1,1,-1,-1};
    int dy[8]={1,0,-1,0,-1,1,1,-1};
                                            using namespace std;
                                   			class pa3{
                                            	public:
                                            	int x;
                                   				int y,z;
                                            	pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
                                            	bool operator < (const pa3 &p) const{
                                            		if(x!=p.x) return x<p.x;
                                            		if(y!=p.y) return y<p.y;
                                            		 return z<p.z;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                   				bool operator > (const pa3 &p) const{
                                            		if(x!=p.x) return x>p.x;
                                            		if(y!=p.y) return y>p.y;
                                            		 return z>p.z;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa3 &p) const{
                                            		return x==p.x && y==p.y && z==p.z;
                                            	}
                                            		bool operator != (const pa3 &p) const{
                                            			return !( x==p.x && y==p.y && z==p.z);
                                            	}

                                            };

                                            class pa4{
                                            	public:
                                            	int x;
                                            	int y,z,w;
                                            	pa4(int x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
                                            	bool operator < (const pa4 &p) const{
                                            		if(x!=p.x) return x<p.x;
                                            		if(y!=p.y) return y<p.y;
                                            		if(z!=p.z)return z<p.z;
                                            		return w<p.w;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator > (const pa4 &p) const{
                                            		if(x!=p.x) return x>p.x;
                                            		if(y!=p.y) return y>p.y;
                                            		if(z!=p.z)return z>p.z;
                                            		return w>p.w;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa4 &p) const{
                                            		return x==p.x && y==p.y && z==p.z &&w==p.w;
                                            	}

                                            };
                                            class pa2{
                                            	public:
                                            	int x,y;
                                            	pa2(int x=0,int y=0):x(x),y(y) {}
                                            	pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
                                            	pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
                                            	bool operator < (const pa2 &p) const{
                                            		return y != p.y ? y<p.y: x<p.x;
                                            	}
                                            	bool operator > (const pa2 &p) const{
                                            		return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa2 &p) const{
                                            		return abs(x-p.x)==0 && abs(y-p.y)==0;
                                            	}
                                            	bool operator != (const pa2 &p) const{
                                            		return !(abs(x-p.x)==0 && abs(y-p.y)==0);
                                            	}

                                            };

                                string itos( int i ) {
                                ostringstream s ;
                                s << i ;
                                return s.str() ;
                                }

                                int gcd(int v,int b){
                                	if(v>b) return gcd(b,v);
                                	if(v==b) return b;
                                	if(b%v==0) return v;
                                	return gcd(v,b%v);
                                }

                                int mod;
int extgcd(int a, int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int d = extgcd(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
pa operator+(const pa & l,const pa & r) {
    return {l.first+r.first,l.second+r.second};
}
pa operator-(const pa & l,const pa & r) {
    return {l.first-r.first,l.second-r.second};
}

                int pr[200010];
                int inv[200010];

                int beki(int wa,int rr,int warukazu){
                	if(rr==0) return 1%warukazu;
                	if(rr==1) return wa%warukazu;
                	wa%=warukazu;
                	if(rr%2==1) return ((ll)beki(wa,rr-1,warukazu)*(ll)wa)%warukazu;
                	ll zx=beki(wa,rr/2,warukazu);
                	return (zx*zx)%warukazu;
                }

    			int comb(int nn,int rr){
    				if(rr<0 || rr>nn || nn<0) return 0;
    				int r=pr[nn]*inv[rr];
    				r%=mod;
    				r*=inv[nn-rr];
    				r%=mod;
    				return r;
    			}

                void gya(int ert){
                	pr[0]=1;
                	for(int i=1;i<=ert;i++){
                		pr[i]=(pr[i-1]*i)%mod;
                	}
                		inv[ert]=beki(pr[ert],mod-2,mod);
                	for(int i=ert-1;i>=0;i--){
                		inv[i]=inv[i+1]*(i+1)%mod;
                	}
                }

              //   cin.tie(0);
    		//	ios::sync_with_stdio(false);
    			//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
                 //sort(ve.begin(),ve.end(),greater<int>());
//    mt19937(clock_per_sec);
  //  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ;

                               //----------------kokomade tenpure------------

int p[5010],c[5001];
int use_q[5010]={};
vector<int> atode[5030];
int con=5010;

vector<pa> G[103030];

bool col[6000]={};

int vis[11010];
int mae[11000];

int x[6020],y[6020];

bool add(int b,int s,int t,int num){
	G[s].pb(mp(t+con,num));
	G[t+con].pb(mp(s,num));

	queue<pa> que;
	for(auto v:G[b])que.push(v);
//	que.push(mp(s,num));
//cout<<s<<" "<<t<<endl;
	while(que.size()){
		pa z=que.front();
		que.pop();
		if(vis[z.first]==num) continue;
		vis[z.first]=num;
		mae[z.first]=z.second;

		if(z.first>=con){
			bool bo=false;
			for(auto v:G[z.first]){
				if(col[v.second]){
					bo=1;
					if(vis[v.first]<num){
						que.push(v);
					}
				}
				if(!bo){
					//

					int ima=z.first;
					while(1){
				//		cout<<ima<<" "<<mae[ima]<<endl;
						if(ima==s) break;
						col[mae[ima]]^=1;
				//		cout<<x[mae[ima]]<<" "<<y[mae[ima]]<<" "<<ima<<endl;
						ima=(x[mae[ima]]^y[mae[ima]]^ima);
					}

					/*
					for(int r=0;r<3;r++)cout<<col[r];
					cout<<endl;
					*/
					return 1;
				}
			}

		}
		else{
			for(auto v:G[z.first]){
				if(col[v.second]==0){

					if(vis[v.first]<num){
						que.push(v);
					}
				}
			}
		}
	}
	return 0;
}

 signed main(){

    	       cin.tie(0);
   		ios::sync_with_stdio(false);
int n,m;
 	cin>>n>>m;
 	for(int i=0;i<11000;i++)vis[i]=-1;
 	for(int i=0;i<n;i++)cin>>p[i];
 	for(int i=0;i<n;i++){
 		cin>>c[i];
 		c[i]--;
 	}
	vector<int> que;
 	int q;
 	cin>>q;
 	for(int i=0;i<q;i++){
 		int y;
 		cin>>y;
 		y--;
 		use_q[y]=1;
 		que.pb(y);
 	}
 	for(int i=0;i<n;i++)if(!use_q[i])que.pb(i);
 	reverse(que.begin(),que.end());

 	vector<int> ans;
 	ans.pb(0);
 	int ima=0;
 	int cnt=0;
 	for(auto v:que){

 		//p[v] -> c[v]
// 		cout<<p[v]<<" "<<c[v]<<endl;
 		if(p[v]<ima){
 				x[cnt]=p[v];
 				y[cnt]=con+c[v];
 		//	G[p[v]].pb({con+c[v],cnt});
 		//		G[con+c[v]].pb({p[v],cnt});
 			bool	f=add(ima,p[v],c[v],cnt);

 			cnt++;

 			if(!f){
 			ans.pb(ima);
 				continue;
 			}
 			ima++;
 	//		cout<<ima<<" "<<p[v]<<" "<<c[v]<<endl;
 	//		cout<<"ha??"<<endl;
 c[v]+=con;
 		}

 		else if(p[v]>=ima){
 		c[v]+=con;
 			atode[p[v]].pb(c[v]);
 		}
 		while(1){
 			int g=ima;
 			bool f=false;
 			while(atode[g].size()){
 	//			cout<<g<<"   "<<atode[g].back()<<endl;
 				if(f){
  					G[g].pb({atode[g].back(),cnt});
 					G[atode[g].back()].pb({g,cnt});
 					x[cnt]=g;
 					y[cnt]=atode[g].back();
 					cnt++;
 					atode[g].pop_back();
 					continue;
 				}
 				 x[cnt]=g;
 				y[cnt]=atode[g].back();
 				f=add(ima,g,atode[g].back()-con,cnt);
/*
 				cout<<"==="<<endl;
	for(int i=0;i<10;i++)for(auto v:G[i]){
		cout<<i<<" "<<v.first-con<<" "<<v.second<<" "<<col[v.second]<<endl;
	}
 */
 				cnt++;
 				atode[g].pop_back();

 			}
 			if(f){
 				ima++;
 				continue;
 			}
 			break;
 		}
 		ans.pb(ima);
 	}
 	ans.pop_back();
 	reverse(ans.begin(),ans.end());
 	for(int i=0;i<q;i++)cout<<ans[i]<<endl;

 }


   #include <bits/stdc++.h>

//    #include <boost/multiprecision/cpp_int.hpp>
 #define int long long
 #define inf  1000000007
 #define pa pair<int,int>
 #define ll long long
 #define pal pair<double,double>
 #define ppap pair<pa,int>
  #define PI 3.14159265358979323846
  #define paa pair<int,char>
  #define  mp make_pair
  #define  pb push_back
  #define EPS (1e-10)

    int dx[8]={0,1,0,-1,1,1,-1,-1};
    int dy[8]={1,0,-1,0,-1,1,1,-1};
                                            using namespace std;
                                   			class pa3{
                                            	public:
                                            	int x;
                                   				int y,z;
                                            	pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
                                            	bool operator < (const pa3 &p) const{
                                            		if(x!=p.x) return x<p.x;
                                            		if(y!=p.y) return y<p.y;
                                            		 return z<p.z;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                   				bool operator > (const pa3 &p) const{
                                            		if(x!=p.x) return x>p.x;
                                            		if(y!=p.y) return y>p.y;
                                            		 return z>p.z;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa3 &p) const{
                                            		return x==p.x && y==p.y && z==p.z;
                                            	}
                                            		bool operator != (const pa3 &p) const{
                                            			return !( x==p.x && y==p.y && z==p.z);
                                            	}

                                            };

                                            class pa4{
                                            	public:
                                            	int x;
                                            	int y,z,w;
                                            	pa4(int x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
                                            	bool operator < (const pa4 &p) const{
                                            		if(x!=p.x) return x<p.x;
                                            		if(y!=p.y) return y<p.y;
                                            		if(z!=p.z)return z<p.z;
                                            		return w<p.w;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator > (const pa4 &p) const{
                                            		if(x!=p.x) return x>p.x;
                                            		if(y!=p.y) return y>p.y;
                                            		if(z!=p.z)return z>p.z;
                                            		return w>p.w;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa4 &p) const{
                                            		return x==p.x && y==p.y && z==p.z &&w==p.w;
                                            	}

                                            };
                                            class pa2{
                                            	public:
                                            	int x,y;
                                            	pa2(int x=0,int y=0):x(x),y(y) {}
                                            	pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
                                            	pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
                                            	bool operator < (const pa2 &p) const{
                                            		return y != p.y ? y<p.y: x<p.x;
                                            	}
                                            	bool operator > (const pa2 &p) const{
                                            		return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa2 &p) const{
                                            		return abs(x-p.x)==0 && abs(y-p.y)==0;
                                            	}
                                            	bool operator != (const pa2 &p) const{
                                            		return !(abs(x-p.x)==0 && abs(y-p.y)==0);
                                            	}

                                            };

                                string itos( int i ) {
                                ostringstream s ;
                                s << i ;
                                return s.str() ;
                                }

                                int gcd(int v,int b){
                                	if(v>b) return gcd(b,v);
                                	if(v==b) return b;
                                	if(b%v==0) return v;
                                	return gcd(v,b%v);
                                }

                                int mod;
int extgcd(int a, int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int d = extgcd(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
pa operator+(const pa & l,const pa & r) {
    return {l.first+r.first,l.second+r.second};
}
pa operator-(const pa & l,const pa & r) {
    return {l.first-r.first,l.second-r.second};
}

                int pr[200010];
                int inv[200010];

                int beki(int wa,int rr,int warukazu){
                	if(rr==0) return 1%warukazu;
                	if(rr==1) return wa%warukazu;
                	wa%=warukazu;
                	if(rr%2==1) return ((ll)beki(wa,rr-1,warukazu)*(ll)wa)%warukazu;
                	ll zx=beki(wa,rr/2,warukazu);
                	return (zx*zx)%warukazu;
                }

    			int comb(int nn,int rr){
    				if(rr<0 || rr>nn || nn<0) return 0;
    				int r=pr[nn]*inv[rr];
    				r%=mod;
    				r*=inv[nn-rr];
    				r%=mod;
    				return r;
    			}

                void gya(int ert){
                	pr[0]=1;
                	for(int i=1;i<=ert;i++){
                		pr[i]=(pr[i-1]*i)%mod;
                	}
                		inv[ert]=beki(pr[ert],mod-2,mod);
                	for(int i=ert-1;i>=0;i--){
                		inv[i]=inv[i+1]*(i+1)%mod;
                	}
                }

              //   cin.tie(0);
    		//	ios::sync_with_stdio(false);
    			//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
                 //sort(ve.begin(),ve.end(),greater<int>());
//    mt19937(clock_per_sec);
  //  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ;

                               //----------------kokomade tenpure------------

int p[5010],c[5001];
int use_q[5010]={};
vector<int> atode[5030];
int con=5010;

vector<pa> G[103030];

bool col[6000]={};

int vis[11010];
int mae[11000];

int x[6020],y[6020];

bool add(int b,int s,int t,int num){
	G[s].pb(mp(t+con,num));
	G[t+con].pb(mp(s,num));

	queue<pa> que;
	for(auto v:G[b])que.push(v);
//	que.push(mp(s,num));

	while(que.size()){
		pa z=que.front();
		que.pop();
		if(vis[z.first]==num) continue;
		vis[z.first]=num;
		mae[z.first]=z.second;

		if(z.first>=con){
			bool bo=false;
			for(auto v:G[z.first]){
		//		cout<<z.first-con<<" "<<v.second<<" "<<col[v.second]<<endl;
				if(col[v.second]){
					bo=1;
					if(vis[v.first]<num){
						que.push(v);
					}

				}
			}
				if(!bo){
					//

					int ima=z.first;
					while(1){
		//				cout<<ima<<" ";
				//		cout<<ima<<" "<<mae[ima]<<endl;
						if(ima==s) break;
						col[mae[ima]]^=1;
				//		cout<<x[mae[ima]]<<" "<<y[mae[ima]]<<" "<<ima<<endl;
						ima=(x[mae[ima]]^y[mae[ima]]^ima);
					}
		//			cout<<endl;
					/*
					for(int r=0;r<3;r++)cout<<col[r];
					cout<<endl;
					*/
					return 1;
				}

		}
		else{
			for(auto v:G[z.first]){
				if(col[v.second]==0){

					if(vis[v.first]<num){
						que.push(v);
					}
				}
			}
		}
	}
	return 0;
}

 signed main(){

    	       cin.tie(0);
   		ios::sync_with_stdio(false);
int n,m;
 	cin>>n>>m;
 	for(int i=0;i<11000;i++)vis[i]=-1;
 	for(int i=0;i<n;i++)cin>>p[i];
 	for(int i=0;i<n;i++){
 		cin>>c[i];
 		c[i]--;
 	}
	vector<int> que;
 	int q;
 	cin>>q;
 	for(int i=0;i<q;i++){
 		int y;
 		cin>>y;
 		y--;
 		use_q[y]=1;
 		que.pb(y);
 	}
 	for(int i=0;i<n;i++)if(!use_q[i])que.pb(i);
 	reverse(que.begin(),que.end());

 	vector<int> ans;
 	ans.pb(0);
 	int ima=0;
 	int cnt=0;
 	for(auto v:que){

 		//p[v] -> c[v]
// 		cout<<p[v]<<" "<<c[v]<<endl;
 		if(p[v]<ima){
 				x[cnt]=p[v];
 				y[cnt]=con+c[v];
 		//	G[p[v]].pb({con+c[v],cnt});
 		//		G[con+c[v]].pb({p[v],cnt});
 			bool	f=add(ima,p[v],c[v],cnt);

 			cnt++;

 			if(!f){
 			ans.pb(ima);
 				continue;
 			}
 			ima++;
 	//		cout<<ima<<" "<<p[v]<<" "<<c[v]<<endl;
 	//		cout<<"ha??"<<endl;
 c[v]+=con;
 		}

 		else if(p[v]>=ima){
 		c[v]+=con;
 			atode[p[v]].pb(c[v]);
 		}
 		while(1){
 			int g=ima;
 			bool f=false;
 			while(atode[g].size()){
 	//			cout<<g<<"   "<<atode[g].back()<<endl;
 				if(f){
  					G[g].pb({atode[g].back(),cnt});
 					G[atode[g].back()].pb({g,cnt});
 					x[cnt]=g;
 					y[cnt]=atode[g].back();
 					cnt++;
 					atode[g].pop_back();
 					continue;
 				}
 				 x[cnt]=g;
 				y[cnt]=atode[g].back();
 				f=add(ima,g,atode[g].back()-con,cnt);
/*
 				cout<<"==="<<endl;
	for(int i=0;i<10;i++)for(auto v:G[i]){
		cout<<i<<" "<<v.first-con<<" "<<v.second<<" "<<col[v.second]<<endl;
	}
 	for(int i=0;i<10;i++)for(auto v:G[con+i]){
		cout<<i<<" "<<v.first<<" "<<v.second<<" "<<col[v.second]<<endl;
	}
 */
 				cnt++;
 				atode[g].pop_back();

 			}
 			if(f){
 				ima++;
 				continue;
 			}
 			break;
 		}
 		ans.pb(ima);
 	}
 	ans.pop_back();
 	reverse(ans.begin(),ans.end());
 	for(int i=0;i<q;i++)cout<<ans[i]<<endl;

 }


#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) x.rbegin(), x.rend()
#define reu(i, a, b) for(ll i = (a); i <= (b); ++i)
#define red(i, a, b) for(ll i = (a); i >= (b); --i)
#define deb(x) cout << #x << ": " << x << "\n"
#define deb2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << "\n"
#define clr(x) memset(x, 0, sizeof x)
#define PI 3.141592653589793238
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef int64_t ll;
typedef deque<int> di;
typedef deque<ll> dll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pll> vpll;
typedef vector<pii> vii;
typedef tuple<ll,ll,ll> iii;
ll inp() {ll x; cin >> x; return x;}
string inp_str() {string x; cin >> x; return x;}
void fast_io() {ios::sync_with_stdio(0); cin.tie(0);}
void file_io(const char *in, const char *out) {
	freopen(in, "r", stdin);
	freopen(out, "w", stdout);
}
void print_bool(bool a, string t = "YES", string f = "NO") {
	if (a) cout << t << "\n";
	else cout << f << "\n";
}
/***Main Code***/
ll n, m;
const ll N = 5e3 + 4;
ll c[N][N], idx[N], p[N], matchY[N];
vll adj[N];
bitset<N> visited;

void Input() {
	cin >> n >> m;
	reu(i, 1, n) cin >> p[i];
	clr(c);
	reu(i, 1, n) adj[i].clear();
	reu(i, 1, n) {
		idx[i] = inp();
		adj[p[i]].pb(idx[i]);
		c[p[i]][idx[i]]++;
	}
}

bool match(ll u) {
	if (visited[u]) return false;
	visited[u] = true;
	for(auto &v : adj[u]) {
		if (c[u][v] == 0) continue;
		if (matchY[v] == -1 || match(matchY[v])) {
			matchY[v] = u;
			return true;
		}
		if (matchY[v] > u) {
			matchY[v] = u;
			return true;
		}
	}
	return false;
}

void Solve() {
	ll d = inp();
	reu(_, 1, d) {
		ll i = inp();
		ll &clb = idx[i];
		c[p[i]][clb]--;
		ll mex;
		memset(matchY, -1, sizeof matchY);
		reu(i, 0, m) {
			visited.reset();
			if (!match(i)) {
				mex = i; cout << mex << "\n";
				break;
			}
		}
	}
}

int main()
{
	fast_io();
//	#define task "test"
//	file_io(task".inp", task".out");
	Input(), Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) x.rbegin(), x.rend()
#define reu(i, a, b) for(ll i = (a); i <= (b); ++i)
#define red(i, a, b) for(ll i = (a); i >= (b); --i)
#define deb(x) cout << #x << ": " << x << "\n"
#define deb2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << "\n"
#define clr(x) memset(x, 0, sizeof x)
#define PI 3.141592653589793238
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef int64_t ll;
typedef deque<int> di;
typedef deque<ll> dll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pll> vpll;
typedef vector<pii> vii;
typedef tuple<ll,ll,ll> iii;
ll inp() {ll x; cin >> x; return x;}
string inp_str() {string x; cin >> x; return x;}
void fast_io() {ios::sync_with_stdio(0); cin.tie(0);}
void file_io(const char *in, const char *out) {
	freopen(in, "r", stdin);
	freopen(out, "w", stdout);
}
void print_bool(bool a, string t = "YES", string f = "NO") {
	if (a) cout << t << "\n";
	else cout << f << "\n";
}
/***Main Code***/
ll n, m;
const ll N = 5e3 + 4;
ll c[N][N], idx[N], p[N], matchY[N];
vll adj[N];
bitset<N> visited;

void Input() {
	cin >> n >> m;
	reu(i, 1, n) cin >> p[i];
	clr(c);
	reu(i, 1, n) adj[i].clear();
	reu(i, 1, n) {
		idx[i] = inp();
		adj[p[i]].pb(idx[i]);
		c[p[i]][idx[i]]++;
	}
}

bool match(ll u) {
	if (visited[u]) return false;
	visited[u] = true;
	for(auto &v : adj[u]) {
		if (c[u][v] == 0) continue;
		if (matchY[v] == -1 || match(matchY[v])) {
			matchY[v] = u;
			return true;
		}
	}
	return false;
}

void Solve() {
	ll d = inp();
	vll st;
	reu(_, 1, d) {
		ll i = inp();
		ll &clb = idx[i];
		c[p[i]][clb]--;
		st.pb(i);
	}
	ll mex;
	memset(matchY, -1, sizeof matchY);
		reu(i, 0, m) {
			visited.reset();
			if (!match(i)) {
				mex = i;
				break;
			}
	}
	vll ans;
	red(i, (ll)st.size()-1, 0) {
		ans.pb(mex);
		ll &s = st[i];
		c[p[s]][idx[s]]++;
		ll tmp = mex;
		reu(u, tmp, m) {
			visited.reset();
			if (!match(u)) {
				mex = u;
				break;
			}
		}
	}
	reverse(all(ans));
	for(auto v : ans) cout << v << "\n";
}

int main()
{
	fast_io();
//	#define task "test"
//	file_io(task".inp", task".out");
	Input(), Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) x.rbegin(), x.rend()
#define reu(i, a, b) for(ll i = (a); i <= (b); ++i)
#define red(i, a, b) for(ll i = (a); i >= (b); --i)
#define deb(x) cout << #x << ": " << x << "\n"
#define deb2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << "\n"
#define clr(x) memset(x, 0, sizeof x)
#define PI 3.141592653589793238
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef int64_t ll;
typedef deque<int> di;
typedef deque<ll> dll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pll> vpll;
typedef vector<pii> vii;
typedef tuple<ll,ll,ll> iii;
ll inp() {ll x; cin >> x; return x;}
string inp_str() {string x; cin >> x; return x;}
void fast_io() {ios::sync_with_stdio(0); cin.tie(0);}
void file_io(const char *in, const char *out) {
	freopen(in, "r", stdin);
	freopen(out, "w", stdout);
}
void print_bool(bool a, string t = "YES", string f = "NO") {
	if (a) cout << t << "\n";
	else cout << f << "\n";
}
/***Main Code***/
ll n, m;
const ll N = 5e3 + 4;
ll c[N][N], idx[N], p[N], matchY[N];
vll adj[N];
bitset<N> visited;

void Input() {
	cin >> n >> m;
	reu(i, 1, n) cin >> p[i];
	clr(c);
	reu(i, 1, n) adj[i].clear();
	reu(i, 1, n) {
		idx[i] = inp();
		adj[p[i]].pb(idx[i]);
		c[p[i]][idx[i]]++;
	}
}

bool match(ll u) {
	if (visited[u]) return false;
	visited[u] = true;
	for(auto &v : adj[u]) {
		if (c[u][v] == 0) continue;
		if (matchY[v] == -1 || match(matchY[v])) {
			matchY[v] = u;
			return true;
		}
	}
	return false;
}

void Solve() {
	ll mex;
	memset(matchY, -1, sizeof matchY);
	reu(i, 0, m) {
		visited.reset();
		if (!match(i)) {
			mex = i;
			break;
		}
	}
	ll d = inp();
	reu(_, 1, d) {
		ll i = inp();
		ll &clb = idx[i];
		c[p[i]][clb]--;
		if (p[i] < mex && matchY[clb] == p[i] && !match(p[i])) mex = p[i];
		cout << mex << "\n";
	}
}

int main()
{
	fast_io();
//	#define task "test"
//	file_io(task".inp", task".out");
	Input(), Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) x.rbegin(), x.rend()
#define reu(i, a, b) for(ll i = (a); i <= (b); ++i)
#define red(i, a, b) for(ll i = (a); i >= (b); --i)
#define deb(x) cout << #x << ": " << x << "\n"
#define deb2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << "\n"
#define clr(x) memset(x, 0, sizeof x)
#define PI 3.141592653589793238
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef int64_t ll;
typedef deque<int> di;
typedef deque<ll> dll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pll> vpll;
typedef vector<pii> vii;
typedef tuple<ll,ll,ll> iii;
ll inp() {ll x; cin >> x; return x;}
string inp_str() {string x; cin >> x; return x;}
void fast_io() {ios::sync_with_stdio(0); cin.tie(0);}
void file_io(const char *in, const char *out) {
	freopen(in, "r", stdin);
	freopen(out, "w", stdout);
}
void print_bool(bool a, string t = "YES", string f = "NO") {
	if (a) cout << t << "\n";
	else cout << f << "\n";
}
/***Main Code***/
ll n, m;
const ll N = 5e3 + 4;
ll c[N][N], idx[N], p[N], matchY[N];
vll adj[N];
bitset<N> visited;

void Input() {
	cin >> n >> m;
	reu(i, 1, n) cin >> p[i];
	clr(c);
	reu(i, 1, n) adj[i].clear();
	reu(i, 1, n) {
		idx[i] = inp();
		adj[p[i]].pb(idx[i]);
		c[p[i]][idx[i]]++;
	}
}

bool match(ll u) {
	if (visited[u]) return false;
	visited[u] = true;
	for(auto &v : adj[u]) {
		if (c[u][v] == 0) continue;
		if (matchY[v] == -1 || match(matchY[v])) {
			matchY[v] = u;
			return true;
		}
	}
	return false;
}

void Solve() {
	ll d = inp();
	reu(_, 1, d) {
		ll i = inp();
		ll &clb = idx[i];
		c[p[i]][clb]--;
		ll mex;
		memset(matchY, -1, sizeof matchY);
		reu(i, 0, m) {
			visited.reset();
			if (!match(i)) {
				mex = i; cout << mex << "\n";
//				if (_ == 3) reu(i, 1, m) deb(matchY[i]);
				break;
			}
		}
	}
}

int main()
{
	fast_io();
//	#define task "test"
//	file_io(task".inp", task".out");
	Input(), Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) x.rbegin(), x.rend()
#define reu(i, a, b) for(ll i = (a); i <= (b); ++i)
#define red(i, a, b) for(ll i = (a); i >= (b); --i)
#define deb(x) cout << #x << ": " << x << "\n"
#define deb2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << "\n"
#define clr(x) memset(x, 0, sizeof x)
#define PI 3.141592653589793238
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef int64_t ll;
typedef deque<int> di;
typedef deque<ll> dll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pll> vpll;
typedef vector<pii> vii;
typedef tuple<ll,ll,ll> iii;
ll inp() {ll x; cin >> x; return x;}
string inp_str() {string x; cin >> x; return x;}
void fast_io() {ios::sync_with_stdio(0); cin.tie(0);}
void file_io(const char *in, const char *out) {
	freopen(in, "r", stdin);
	freopen(out, "w", stdout);
}
void print_bool(bool a, string t = "YES", string f = "NO") {
	if (a) cout << t << "\n";
	else cout << f << "\n";
}
/***Main Code***/
ll n, m;
const ll N = 5e3 + 4;
ll c[N][N], idx[N], p[N], matchY[N];
vll adj[N];
bitset<N> visited;

void Input() {
	cin >> n >> m;
	reu(i, 1, n) cin >> p[i];
	clr(c);
	reu(i, 1, n) adj[i].clear();
	reu(i, 1, n) {
		idx[i] = inp();
		adj[p[i]].pb(idx[i]);
		c[p[i]][idx[i]]++;
	}
}

bool match(ll u) {
	if (visited[u]) return false;
	visited[u] = true;
	for(auto &v : adj[u]) {
		if (c[u][v] == 0) continue;
		if (matchY[v] == -1 || match(matchY[v])) {
			matchY[v] = u;
			return true;
		}
	}
	return false;
}

void Solve() {
	ll d = inp();
	ll mex;
	reu(_, 1, d) {
		ll i = inp();
		ll &clb = idx[i];
		c[p[i]][clb]--;
		if (c[p[i]][clb]) {
			cout << mex << "\n";
			continue;
		}
		memset(matchY, -1, sizeof matchY);
		reu(i, 0, m) {
			visited.reset();
			if (!match(i)) {
				mex = i; cout << mex << "\n";
//				if (_ == 3) reu(i, 1, m) deb(matchY[i]);
				break;
			}
		}
	}
}

int main()
{
	fast_io();
//	#define task "test"
//	file_io(task".inp", task".out");
	Input(), Solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef struct{
	int to,nxt;
}edge;
edge e[400011];
int cnt,head[400011],f[400011],vis[400011],p[400011],c[400011],peo[400011],n,m,d,day[400011],ans[400011];
void add(int a,int b){
	cnt++;
	e[cnt].nxt=head[a];
	e[cnt].to=b;
	head[a]=cnt;
}
bool dfs(int u,int p){
	for(int i=head[u];i!=-1;i=e[i].nxt){
		int v=e[i].to;
		if(vis[v]==p)continue;
		vis[v]=p;
		if(f[v]==-1||dfs(f[v],p)){
			f[v]=u;
			return 1;
		}
	}
	return 0;
}
int main(){
	memset(head,-1,sizeof(head));
	memset(f,-1,sizeof(f));
	memset(vis,0,sizeof(vis));
	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",&day[i]);
		peo[day[i]]=true;
	}
	for(int i=1;i<=n;i++)
	  if(!peo[i]){
	  	add(p[i],c[i]+10001);
	  }
	int mex=0;int tim=1;
	for(int i=d;i>=1;i--){
		while(mex<=5000&&dfs(mex,tim)){
			tim++;
			mex++;
		}
		ans[i]=mex;
		add(p[day[i]],c[day[i]]+10001);
	}
	for(int i=1;i<=d;i++)
	  printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
typedef struct{
	int to,nxt;
}edge;
edge e[400011];
int cnt,head[400011],f[400011],vis[400011],p[400011],c[400011],peo[400011],n,m,d,day[400011],ans[400011];
void add(int a,int b){
	cnt++;
	e[cnt].nxt=head[a];
	e[cnt].to=b;
	head[a]=cnt;
}
bool dfs(int u,int p){
	for(int i=head[u];i!=-1;i=e[i].nxt){
		int v=e[i].to;
		if(vis[v]==p)continue;
		vis[v]=p;
		if(f[v]==-1||dfs(f[v],p)){
			f[v]=u;
			return 1;
		}
	}
	return 0;
}
int main(){
	memset(head,-1,sizeof(head));
	memset(f,-1,sizeof(f));
	memset(vis,0,sizeof(vis));
	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",&day[i]);
		peo[day[i]]=true;
	}
	for(int i=1;i<=n;i++)
	  if(!peo[i]){
	  	add(p[i],c[i]+10001);
	  }
	int mex=0;
	for(int i=d;i>=1;i--){
		while(mex<=5000&&dfs(mex,i)){
			mex++;
		}
		ans[i]=mex;
		add(p[day[i]],c[day[i]]+10001);
	}
	for(int i=1;i<=d;i++)
	  printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
typedef struct{
	int to,nxt;
}edge;
edge e[400011];
int cnt,head[400011],f[400011],vis[400011],p[400011],c[400011],peo[400011],n,m,d,day[400011],ans[400011];
void add(int a,int b){
	cnt++;
	e[cnt].nxt=head[a];
	e[cnt].to=b;
	head[a]=cnt;
}
bool dfs(int u,int p){
	for(int i=head[u];i!=-1;i=e[i].nxt){
		int v=e[i].to;
		if(vis[v]==p)continue;
		vis[v]=p;
		if(f[v]==-1||dfs(f[v],p)){
			f[v]=u;
			return 1;
		}
	}
	return 0;
}
int main(){
	memset(head,-1,sizeof(head));
	memset(f,-1,sizeof(f));
	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",&day[i]);
		peo[day[i]]=true;
	}
	for(int i=1;i<=n;i++)
	  if(!peo[i]){
	  	add(p[i],c[i]+5001);
	  }
	int mex=0;
	for(int i=d;i>=1;i--){
		while(mex<=5000&&dfs(mex,i)){
			mex++;
		}
		ans[i]=mex;
		add(p[day[i]],c[day[i]]+5001);
	}
	for(int i=1;i<=d;i++)
	  printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
typedef struct{
	int to,nxt;
}edge;
edge e[400011];
int cnt,head[400011],f[400011],vis[400011],p[400011],c[400011],peo[400011],n,m,d,day[400011],ans[400011];
void add(int a,int b){
	cnt++;
	e[cnt].nxt=head[a];
	e[cnt].to=b;
	head[a]=cnt;
}
bool dfs(int u,int p){
	for(int i=head[u];i!=-1;i=e[i].nxt){
		int v=e[i].to;
		if(vis[v]==p)continue;
		vis[v]=p;
		if(!f[v]||dfs(f[v],p)){
			f[v]=u;
			return 1;
		}
	}
	return 0;
}
int main(){
	memset(head,-1,sizeof(head));
	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",&day[i]);
		peo[day[i]]=true;
	}
	for(int i=1;i<=n;i++)
	  if(!peo[i]){
	  	add(p[i],c[i]+5001);
	  }
	int mex=0;
	for(int i=d;i>=1;i--){
		while(mex<=5000&&dfs(mex,i)){
			mex++;
		}
		ans[i]=mex;
		add(p[day[i]],c[day[i]]+5000);
	}
	for(int i=1;i<=d;i++)
	  printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
typedef struct{
	int to,nxt;
}edge;
edge e[400011];
int cnt,tim,head[400011],f[400011],vis[400011],p[400011],c[400011],peo[400011],n,m,d,day[400011],ans[400011];
void add(int a,int b){
	cnt++;
	e[cnt].nxt=head[a];
	e[cnt].to=b;
	head[a]=cnt;
}
bool dfs(int u,int p){
	for(int i=head[u];i!=-1;i=e[i].nxt){
		int v=e[i].to;
		if(vis[v]==p)continue;
		vis[v]=p;
		if(f[v]==-1||dfs(f[v],p)){
			f[v]=u;
			return 1;
		}
	}
	return 0;
}
int main(){
	memset(head,-1,sizeof(head));
	memset(f,-1,sizeof(f));
	memset(vis,0,sizeof(vis));
	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",&day[i]);
		peo[day[i]]=true;
	}
	for(int i=1;i<=n;i++)
	  if(!peo[i]){
	  	add(p[i],c[i]+10001);
	  }
	int mex=0;tim=1;
	for(int i=d;i>=1;i--){
		while(++tim,mex<=5000&&dfs(mex,tim)){
			mex++;
		}
		ans[i]=mex;
		add(p[day[i]],c[day[i]]+10001);
	}
	for(int i=1;i<=d;i++)
	  printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
typedef struct{
	int to,nxt;
}edge;
edge e[400011];
int cnt,head[400011],f[400011],vis[400011],p[400011],c[400011],peo[400011],n,m,d,day[400011],ans[400011];
void add(int a,int b){
	cnt++;
	e[cnt].nxt=head[a];
	e[cnt].to=b;
	head[a]=cnt;
}
bool dfs(int u,int p){
	for(int i=head[u];i!=-1;i=e[i].nxt){
		int v=e[i].to;
		if(vis[v]==p)continue;
		vis[v]=p;
		if(!f[v]||dfs(f[v],p)){
			f[v]=u;
			return 1;
		}
	}
	return 0;
}
int main(){
	memset(head,-1,sizeof(head));
	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",&day[i]);
		peo[day[i]]=true;
	}
	for(int i=1;i<=n;i++)
	  if(!peo[i]){
	  	add(p[i],c[i]+5001);
	  }
	int mex=0;
	for(int i=d;i>=1;i--){
		while(mex<=5000&&dfs(mex,i)){
			mex++;
		}
		ans[i]=mex;
		add(p[day[i]],c[day[i]]+5001);
	}
	for(int i=1;i<=d;i++)
	  printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
typedef struct{
	int to,nxt;
}edge;
edge e[400011];
int cnt,head[400011],f[400011],vis[400011],p[400011],c[400011],peo[400011],n,m,d,day[400011],ans[400011];
void add(int a,int b){
	cnt++;
	e[cnt].nxt=head[a];
	e[cnt].to=b;
	head[a]=cnt;
}
bool dfs(int u,int p){
	for(int i=head[u];i!=-1;i=e[i].nxt){
		int v=e[i].to;
		if(vis[v]==p)continue;
		vis[v]=p;
		if(f[v]==-1||dfs(f[v],p)){
			f[v]=u;
			return 1;
		}
	}
	return 0;
}
int main(){
	memset(head,-1,sizeof(head));
	memset(f,-1,sizeof(f));
	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",&day[i]);
		peo[day[i]]=true;
	}
	for(int i=1;i<=n;i++)
	  if(!peo[i]){
	  	add(p[i],c[i]+10001);
	  }
	int mex=0;
	for(int i=d;i>=1;i--){
		while(mex<=5000&&dfs(mex,i)){
			mex++;
		}
		ans[i]=mex;
		add(p[day[i]],c[day[i]]+10001);
	}
	for(int i=1;i<=d;i++)
	  printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
typedef struct{
	int to,nxt;
}edge;
edge e[400011];
int cnt,tim,head[400011],f[400011],vis[400011],p[400011],c[400011],peo[400011],n,m,d,day[400011],ans[400011];
void add(int a,int b){
	cnt++;
	e[cnt].nxt=head[a];
	e[cnt].to=b;
	head[a]=cnt;
}
bool dfs(int u,int p){
	for(int i=head[u];i!=-1;i=e[i].nxt){
		int v=e[i].to;
		if(vis[v]==p)continue;
		vis[v]=p;
		if(f[v]==-1||dfs(f[v],p)){
			f[v]=u;
			return 1;
		}
	}
	return 0;
}
int main(){
	memset(head,-1,sizeof(head));
	memset(f,-1,sizeof(f));
	memset(vis,0,sizeof(vis));
	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",&day[i]);
		peo[day[i]]=true;
	}
	for(int i=1;i<=n;i++)
	  if(!peo[i]){
	  	add(p[i],c[i]+10001);
	  }
	int mex=0;tim=1;
	for(int i=d;i>=1;i--){
		while(++tim,mex<=5000&&dfs(mex,tim)){
			mex++;
		}
		ans[i]=mex;
		add(p[day[i]],c[day[i]]+10001);
	}
	for(int i=1;i<=d;i++)
	  printf("%d\n",ans[i]);//same
}


#include<bits/stdc++.h>
using namespace std;
typedef struct{
	int to,nxt;
}edge;
edge e[400011];
int cnt,head[400011],f[400011],vis[400011],p[400011],c[400011],peo[400011],n,m,d,day[400011],ans[400011];
void add(int a,int b){
	cnt++;
	e[cnt].nxt=head[a];
	e[cnt].to=b;
	head[a]=cnt;
}
bool dfs(int u,int p){
	for(int i=head[u];i!=-1;i=e[i].nxt){
		int v=e[i].to;
		if(vis[v]==p)continue;
		vis[v]=p;
		if(f[v]==-1||dfs(f[v],p)){
			f[v]=u;
			return 1;
		}
	}
	return 0;
}
int main(){
	memset(head,-1,sizeof(head));
	memset(f,-1,sizeof(f));
	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",&day[i]);
		peo[day[i]]=true;
	}
	for(int i=1;i<=n;i++)
	  if(!peo[i]){
	  	add(p[i],c[i]+10001);
	  	add(c[i]+10001,p[i]);
	  }
	int mex=0;
	for(int i=d;i>=1;i--){
		while(mex<=5000&&dfs(mex,i)){
			mex++;
		}
		ans[i]=mex;
		add(p[day[i]],c[day[i]]+10001);
		add(c[day[i]]+10001,p[day[i]]);
	}
	for(int i=1;i<=d;i++)
	  printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
typedef struct{
	int to,nxt;
}edge;
edge e[400011];
int cnt,head[400011],f[400011],vis[400011],p[400011],c[400011],peo[400011],n,m,d,day[400011],ans[400011];
void add(int a,int b){
	cnt++;
	e[cnt].nxt=head[a];
	e[cnt].to=b;
	head[a]=cnt;
}
bool dfs(int u,int p){
	for(int i=head[u];i!=-1;i=e[i].nxt){
		int v=e[i].to;
		if(vis[v]==p)continue;
		vis[v]=p;
		if(!f[v]||dfs(f[v],p)){
			f[v]=u;
			return 1;
		}
	}
	return 0;
}
int main(){
	memset(head,-1,sizeof(head));
	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",&day[i]);
		peo[day[i]]=true;
	}
	for(int i=1;i<=n;i++)
	  if(!peo[i]){
	  	add(p[i],c[i]+5001);
	  }
	int mex=0;
	for(int i=n;i>=1;i--){
		while(mex<=5000&&dfs(mex,i)){
			mex++;
		}
		ans[i]=mex;
		add(p[day[i]],c[day[i]]+5000);
	}
	for(int i=1;i<=n;i++)
	  printf("%d\n",ans[i]);
}


#include<iostream>
using namespace std;
int a[1000005],b[1000005],zyl[1000005],ans[1000005]; //a能力b组zyl离开。
struct xyq{
	int v,next;
}_[1000005];
int head[1000005],tot=1;
void add(int u,int v){
	_[tot].v=v;
	_[tot].next=head[u];
	head[u]=tot;
	++tot;
}
int kkksc03[1000005];
bool mark[1000005];
bool dfs(int iakioi){
	int i;
	for(i=head[iakioi];i;i=_[i].next){
		if(!mark[_[i].v]){
			mark[_[i].v]=1;
			if(kkksc03[_[i].v]<0||dfs(kkksc03[_[i].v])){
				kkksc03[_[i].v]=iakioi;
				return true;
			}
		}
	}
	return false;
}
int n,m;
int Main(int l){
	int i,j;
	for(i=0;i<=5555;++i){
		kkksc03[i]=-1;
	}
	for(i=l;i<=5001;++i){
		for(j=0;j<=m;++j){
			mark[j]=0;
		}
		if(!dfs(i)){
			return i;
		}
	}
}
bool hyy[1000005];
int main(){
	int d,i,ykb;
	cin>>n>>m;
	for(i=0;i<n;++i){
		cin>>a[i];
	}
	for(i=0;i<n;++i){
		cin>>b[i];
//		cout<<b[i]<<" ";
	}
//	cout<<endl;
	cin>>d;
	for(i=0;i<d;++i){
		cin>>zyl[i];
		hyy[zyl[i]]=1;
//		cout<<"zyl="<<zyl[i]<<endl;
	}
	for(i=1;i<=n;++i){
//		cout<<hyy[i]<<" ";
		if(!hyy[i]){
			add(a[i-1],b[i-1]);
		}
	}
	ans[d]=Main(0);
//	cout<<endl;
	for(i=d-1;i>=0;--i){
		add(a[zyl[i]-1],b[zyl[i]-1]);
		ans[i]=Main(ans[i+1]);
//		cout<<"i="<<i<<",zyl="<<zyl[i]<<",连接"<<a[zyl[i]-1]<<"和"<<b[zyl[i]-1]<<",ans="<<ans[i]<<endl;
	}
	for(i=1;i<=d;++i){
		cout<<ans[i]<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int a[1000005],b[1000005],zyl[1000005],ans[1000005]; //a能力b组zyl离开。
struct xyq{
	int v,next;
}_[1000005];
int head[1000005],tot=1;
void add(int u,int v){
	_[tot].v=v;
	_[tot].next=head[u];
	head[u]=tot;
	++tot;
}
int kkksc03[1000005];
bool mark[1000005];
bool dfs(int iakioi){
	int i;
	for(i=head[iakioi];i;i=_[i].next){
		if(!mark[_[i].v]){
			mark[_[i].v]=1;
			if(kkksc03[_[i].v]<0||dfs(kkksc03[_[i].v])){
				kkksc03[_[i].v]=iakioi;
				return true;
			}
		}
	}
	return false;
}
int n,m;
int Main(){
	int i,j;
	for(i=0;i<=5555;++i){
		kkksc03[i]=-1;
	}
	for(i=0;i<=5001;++i){
		for(j=0;j<=m;++j){
			mark[j]=0;
		}
		if(!dfs(i)){
			return i;
		}
	}
}
bool hyy[1000005];
int main(){
	int d,i,ykb;
	cin>>n>>m;
	for(i=0;i<n;++i){
		cin>>a[i];
	}
	for(i=0;i<n;++i){
		cin>>b[i];
//		cout<<b[i]<<" ";
	}
//	cout<<endl;
	cin>>d;
	for(i=0;i<d;++i){
		cin>>zyl[i];
		hyy[zyl[i]]=1;
//		cout<<"zyl="<<zyl[i]<<endl;
	}
	for(i=1;i<=n;++i){
//		cout<<hyy[i]<<" ";
		if(!hyy[i]){
			add(a[i-1],b[i-1]);
		}
	}
	ykb=Main();
//	cout<<endl;
	for(i=d-1;i>=0;--i){
		add(a[zyl[i]-1],b[zyl[i]-1]);
		ans[i]=Main();
//		cout<<"i="<<i<<",zyl="<<zyl[i]<<",连接"<<a[zyl[i]-1]<<"和"<<b[zyl[i]-1]<<",ans="<<ans[i]<<endl;
	}
	for(i=1;i<d;++i){
		cout<<ans[i]<<endl;
	}
	cout<<ykb;
	return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#include<bitset>
#include<functional>
#define ll long long
const int N=5005;
using namespace std;

int p[N],c[N],k[N];
int my[N],vis[N];
int ans[N];

int a[N][N],m;
vector<int> g[N];
bool dfs(int x){
	vis[x]=true;
	for(int i=0;i<g[x].size();i++){
		int u=g[x][i],v=my[u];
		if(v==-1 || !vis[v] && dfs(v)){
			my[u]=x;
			return true;
		}
	}
	return false;
}
int main(){
	int n,d;
	scanf("%d%d",&n,&m);
	int i,j;
	for(i=0;i<n;i++) scanf("%d",&p[i]);
	for(i=0;i<n;i++) {
		scanf("%d",&c[i]);
		c[i]--;
		a[p[i]][c[i]]++;
	}
	scanf("%d",&d);
	for(i=0;i<d;i++) {
		scanf("%d",&k[i]);k[i]--;
		a[p[k[i]]][c[k[i]]]--;
	}
	for(i=0;i<N;i++)
		for(j=0;j<m;j++)
			if(a[i][j]>0) {g[i].push_back(j);}

	memset(my,-1,sizeof(my));
	int cur;
	for(cur=0;;cur++){
		memset(vis,false,sizeof(vis));
		if(!dfs(cur)) break;
	}
	ans[d-1]=cur;
	for(i=d-1;i>0;i--){
		if(a[p[k[i]]][c[k[i]]]==0) g[p[k[i]]].push_back(c[k[i]]);
		a[p[k[i]]][c[k[i]]]++;
		memset(vis,false,sizeof(vis));
		while(dfs(cur)) {cur++;memset(vis,false,sizeof(vis));}
		ans[i-1]=cur;
	}
	for(i=0;i<d;i++) printf("%d\n",ans[i]);
	return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#include<bitset>
#include<functional>
#define ll long long
const int N=5005;
using namespace std;

int p[N],c[N],k[N];
int my[N],vis[N];
int ans[N];

int a[N][N],m;
vector<int> g[N];
bool dfs(int x){
	vis[x]=true;
	for(int i=0;i<g[x].size();i++){
		int u=g[x][i],v=my[u];
		if(v==-1 || !vis[v] && dfs(v)){
			my[u]=x;
			return true;
		}
	}
	return false;
}
int main(){
	int n,d;
	scanf("%d%d",&n,&m);
	int i,j;
	for(i=0;i<n;i++) scanf("%d",&p[i]);
	for(i=0;i<n;i++) {
		scanf("%d",&c[i]);
		c[i]--;
		a[p[i]][c[i]]++;
	}
	scanf("%d",&d);
	for(i=0;i<d;i++) {
		scanf("%d",&k[i]);k[i]--;
		a[p[k[i]]][c[k[i]]]--;
	}
	for(i=0;i<N;i++)
		for(j=0;j<m;j++)
			if(a[i][j]>0) {g[i].push_back(j);}

	memset(my,-1,sizeof(my));
	int cur;
	for(cur=0;;cur++){
		memset(vis,false,sizeof(vis));
		if(!dfs(cur)) break;
	}
	ans[d-1]=cur;
	for(i=d-1;i>0;i--){
		if(a[p[k[i]]][c[k[i]]]==0) g[p[k[i]]].push_back(c[k[i]]);
		a[p[k[i]]][c[k[i]]]++;
		memset(vis,false,sizeof(vis));
		while(dfs(cur)) cur++;
		ans[i-1]=cur;
	}
	for(i=0;i<d;i++) printf("%d\n",ans[i]);
	return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#include<bitset>
#include<functional>
#define ll long long
const int N=5005;
using namespace std;

int p[N],c[N],k[N];
int my[N],vis[N];
int ans[N];

int a[N][N],m;
vector<int> g[N];
bool dfs(int x){
	for(int i=0;i<g[x].size();i++){
		int u=g[x][i],v=my[u];
		if(vis[u]) continue;
		vis[u]=true;
		if(v==-1 || dfs(v)){
			my[u]=x;
			return true;
		}
	}
	return false;
}
int main(){
	int n,d;
	scanf("%d%d",&n,&m);
	int i,j;
	for(i=0;i<n;i++) scanf("%d",&p[i]);
	for(i=0;i<n;i++) {
		scanf("%d",&c[i]);
		c[i]--;
		a[p[i]][c[i]]++;
	}
	scanf("%d",&d);
	for(i=0;i<d;i++) {
		scanf("%d",&k[i]);k[i]--;
		a[p[k[i]]][c[k[i]]]--;
	}
	for(i=0;i<N;i++)
		for(j=0;j<m;j++)
			if(a[i][j]>0) {g[i].push_back(j);}

	memset(my,-1,sizeof(my));
	int cur;
	for(cur=0;;cur++){
		memset(vis,false,sizeof(vis));
		if(!dfs(cur)) break;
	}
	ans[d-1]=cur;
	for(i=d-1;i>0;i--){
		if(a[p[k[i]]][c[k[i]]]==0) g[p[k[i]]].push_back(c[k[i]]);
		a[p[k[i]]][c[k[i]]]++;
		memset(vis,false,sizeof(vis));
		while(dfs(cur)) cur++;
		ans[i-1]=cur;
	}
	for(i=0;i<d;i++) printf("%d\n",ans[i]);
	return 0;
}


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iterator>
#include<iostream>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<utility>
#include<bitset>
#include<functional>
#define ll long long
const int N=5005;
using namespace std;

int p[N],c[N],k[N];
int mx[N],my[N],vis[N];
int ans[N];

int g[N][N],m;

bool dfs(int x){
	vis[x]=true;
	for(int i=0;i<m;i++){
		if(g[x][i]==0) continue;
		int v=my[i];
		if(v==-1 || !vis[v] && dfs(v)){
			my[i]=x;
			mx[x]=i;
			return true;
		}
	}
	return false;
}
int main(){
	int n,d;
	scanf("%d%d",&n,&m);
	int i,j;
	for(i=0;i<n;i++) scanf("%d",&p[i]);
	for(i=0;i<n;i++) {
		scanf("%d",&c[i]);
		c[i]--;
		g[p[i]][c[i]]++;
	}
	scanf("%d",&d);
	for(i=0;i<d;i++) {
		scanf("%d",&k[i]);k[i]--;
		g[p[k[i]]][c[k[i]]]--;
	}

	memset(mx,-1,sizeof(mx));
	memset(my,-1,sizeof(my));
	int cur;
	for(cur=0;;cur++){
		memset(vis,false,sizeof(vis));
		if(!dfs(cur)) break;
	}
	ans[d-1]=cur;
	for(i=d-1;i>0;i--){
		g[p[k[i]]][c[k[i]]]++;
		memset(vis,false,sizeof(vis));
		while(dfs(cur)) cur++;
		ans[i-1]=cur;
	}
	for(i=0;i<d;i++) printf("%d\n",ans[i]);
	return 0;
}


#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<ll,ll>
	#define PB push_back
	#define vc vector
	void chmax(int &x,const int y) {x=x>y?x:y;}
	void chmin(int &x,const int y) {x=x<y?x:y;}
	const int MAX_N=5e3+10;
	const ll MOD=998244353;
	void add(ll &x,ll y){x+=y;if(x>=MOD) x-=MOD;if(x<=-MOD) x+=MOD;}
	ll qpower(ll x,ll e)
	{
		ll ans=1;x%=MOD;
		while(e)
		{
			if(e&1) ans=ans*x%MOD;
			x=x*x%MOD;e>>=1;
		}
		return ans;
	}
	ll inv2(ll x){return qpower(x,MOD-2);}

	int hou[MAX_N];
	struct Edge{int y,c,g;}e[MAX_N*10];
	int ln;int oth(int x){return x&1?x+1:x-1;}
	void ins(int x,int y)
	{
		e[++ln]=(Edge){y,1,hou[x]};hou[x]=ln;
		e[++ln]=(Edge){x,0,hou[y]};hou[y]=ln;
	}
	int st,ed;
	int h[MAX_N];queue<int> q;
	bool bfs()
	{
		memset(h,0,sizeof h);h[st]=1;q.push(st);
		while(q.size())
		{
			int x=q.front();q.pop();
			for(int k=hou[x];k>0;k=e[k].g)
			{
				int y=e[k].y;
				if(h[y]==0 and e[k].c>0) h[y]=h[x]+1,q.push(y);
			}
		}
		return h[ed]>0;
	}
	int dfs(int x,int ff)
	{
		if(x==ed) return ff;
		int flow=0;
		for(int k=hou[x];k>0;k=e[k].g)
		{
			int y=e[k].y;
			if(h[y]==h[x]+1 and e[k].c>0)
			{
				int out=dfs(y,min(e[k].c,ff-flow));
				e[k].c-=out;e[oth(k)].c+=out;flow+=out;
			}
			if(flow==ff) break;
		}
		return flow;
	}
	int now=0;
	void update()
	{
		while(bfs()) now+=dfs(st,INF);
	}

	pr a[MAX_N];int ban[MAX_N];bool vis[MAX_N];
	int ans[MAX_N];
	void main()
	{
		int n=qread(),m=qread();st=5000+m+2;ed=5000+m+1;
		for(int i=1;i<=n;i++) a[i].FR=qread();
		for(int i=1;i<=n;i++) a[i].SE=qread();
		int dd=qread();for(int i=1;i<=dd;i++) ban[i]=qread(),vis[ban[i]]=1;
		for(int i=1;i<=m;i++) ins(5000+i,ed);
		for(int i=1;i<=n;i++) if(!vis[i]) ins(a[i].FR,5000+a[i].SE);

		int wt=0;ins(st,wt);
		for(int i=dd;i>=1;i--)
		{
			update();
			while(now==wt+1) wt++,ins(st,wt),update()/*,printf("i=%d wt=%d\n",i,wt)*/;
			ans[i]=wt;

			int x=ban[i];ins(a[x].FR,5000+a[x].SE);
		}
		for(int i=1;i<=dd;i++) write2(ans[i]);
	}
};
/*
5 3
0 1 2 2 0
1 2 2 3 2
5
3
2
4
5
1

3
1
1
1
0

*/
signed main()
{
	srand(time(0));
	mine::main();
}


#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<ll,ll>
	#define PB push_back
	#define vc vector
	void chmax(int &x,const int y) {x=x>y?x:y;}
	void chmin(int &x,const int y) {x=x<y?x:y;}
	const int MAX_N=5e3+10;
	const ll MOD=998244353;
	void add(ll &x,ll y){x+=y;if(x>=MOD) x-=MOD;if(x<=-MOD) x+=MOD;}
	ll qpower(ll x,ll e)
	{
		ll ans=1;x%=MOD;
		while(e)
		{
			if(e&1) ans=ans*x%MOD;
			x=x*x%MOD;e>>=1;
		}
		return ans;
	}
	ll inv2(ll x){return qpower(x,MOD-2);}

	int hou[MAX_N*2];
	struct Edge{int y,c,g;}e[MAX_N*10];
	int ln;int oth(int x){return x&1?x+1:x-1;}
	void ins(int x,int y)
	{
		e[++ln]=(Edge){y,1,hou[x]};hou[x]=ln;
		e[++ln]=(Edge){x,0,hou[y]};hou[y]=ln;
	}
	int st,ed;
	int h[MAX_N*2],cur[MAX_N*2];queue<int> q;
	bool bfs()
	{
	//	memset(cur,0,sizeof cur);
	memcpy(cur,hou,sizeof hou);
		memset(h,0,sizeof h);
		h[st]=1;q.push(st);
		while(q.size())
		{
			int x=q.front();q.pop();
			for(int k=hou[x];k>0;k=e[k].g)
			{
				int y=e[k].y;
				if(h[y]==0 and e[k].c>0) h[y]=h[x]+1,q.push(y);
			}
		}
		return h[ed]>0;
	}
	int dfs(int x,int ff)
	{
		if(x==ed) return ff;
		int flow=0;
		for(int k=cur[x];k>0;k=e[k].g)
		{
			int y=e[k].y;
			if(h[y]==h[x]+1 and e[k].c>0)
			{
				int out=dfs(y,min(e[k].c,ff-flow));
				e[k].c-=out;e[oth(k)].c+=out;flow+=out;
			}
			if(e[k].c==0) cur[x]=e[k].g;
			if(flow==ff) break;
		}
		if(ff==0) h[x]=0;
		return flow;
	}
	int now=0;
	void update()
	{
		while(bfs()) now+=dfs(st,INF);
	}

	pr a[MAX_N];int ban[MAX_N];bool vis[MAX_N];
	int ans[MAX_N];
	void main()
	{
		int n=qread(),m=qread();st=5000+m+2;ed=5000+m+1;
		for(int i=1;i<=n;i++) a[i].FR=qread();
		for(int i=1;i<=n;i++) a[i].SE=qread();
		int dd=qread();for(int i=1;i<=dd;i++) ban[i]=qread(),vis[ban[i]]=1;
		for(int i=1;i<=m;i++) ins(5000+i,ed);
		for(int i=1;i<=n;i++) if(!vis[i]) ins(a[i].FR,5000+a[i].SE);

		int wt=0;ins(st,wt);
		for(int i=dd;i>=1;i--)
		{
			update();
			while(now==wt+1) wt++,ins(st,wt),update()/*,printf("i=%d wt=%d\n",i,wt)*/;
			ans[i]=wt;
			int x=ban[i];ins(a[x].FR,5000+a[x].SE);
		}
		for(int i=1;i<=dd;i++) write2(ans[i]);
	}
};
signed main()
{
	srand(time(0));
	mine::main();
}


#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<ll,ll>
	#define PB push_back
	#define vc vector
	void chmax(int &x,const int y) {x=x>y?x:y;}
	void chmin(int &x,const int y) {x=x<y?x:y;}
	const int MAX_N=5e3+10;
	const ll MOD=998244353;
	void add(ll &x,ll y){x+=y;if(x>=MOD) x-=MOD;if(x<=-MOD) x+=MOD;}
	ll qpower(ll x,ll e)
	{
		ll ans=1;x%=MOD;
		while(e)
		{
			if(e&1) ans=ans*x%MOD;
			x=x*x%MOD;e>>=1;
		}
		return ans;
	}
	ll inv2(ll x){return qpower(x,MOD-2);}

	int hou[MAX_N*2];
	struct Edge{int y,c,g;}e[MAX_N*10];
	int ln;int oth(int x){return x&1?x+1:x-1;}
	void ins(int x,int y)
	{
		e[++ln]=(Edge){y,1,hou[x]};hou[x]=ln;
		e[++ln]=(Edge){x,0,hou[y]};hou[y]=ln;
	}
	int st,ed;
	int h[MAX_N*2],cur[MAX_N*2];queue<int> q;
	bool bfs()
	{
	//	memset(cur,0,sizeof cur);
		memset(h,0,sizeof h);
		h[st]=1;q.push(st);
		while(q.size())
		{
			int x=q.front();q.pop();
			for(int k=hou[x];k>0;k=e[k].g)
			{
				int y=e[k].y;
				if(h[y]==0 and e[k].c>0) h[y]=h[x]+1,q.push(y);
			}
		}
		return h[ed]>0;
	}
	int dfs(int x,int ff)
	{
		if(x==ed) return ff;
		int flow=0;
		for(int k=hou[x];k>0;k=e[k].g)
		{
			int y=e[k].y;
			if(h[y]==h[x]+1 and e[k].c>0)
			{
				int out=dfs(y,min(e[k].c,ff-flow));
				e[k].c-=out;e[oth(k)].c+=out;flow+=out;
			}
			if(flow==ff) break;
		}
		if(ff==0) h[x]=0;
		return flow;
	}
	int now=0;
	void update()
	{
		while(bfs()) now+=dfs(st,INF);
	}

	pr a[MAX_N];int ban[MAX_N];bool vis[MAX_N];
	int ans[MAX_N];
	void main()
	{
		int n=qread(),m=qread();st=5000+m+2;ed=5000+m+1;
		for(int i=1;i<=n;i++) a[i].FR=qread();
		for(int i=1;i<=n;i++) a[i].SE=qread();
		int dd=qread();for(int i=1;i<=dd;i++) ban[i]=qread(),vis[ban[i]]=1;
		for(int i=1;i<=m;i++) ins(5000+i,ed);
		for(int i=1;i<=n;i++) if(!vis[i]) ins(a[i].FR,5000+a[i].SE);

		int wt=0;ins(st,wt);
		for(int i=dd;i>=1;i--)
		{
			update();
			while(now==wt+1) wt++,ins(st,wt),update()/*,printf("i=%d wt=%d\n",i,wt)*/;
			ans[i]=wt;
			int x=ban[i];ins(a[x].FR,5000+a[x].SE);
		}
		for(int i=1;i<=dd;i++) write2(ans[i]);
	}
};
signed main()
{
	srand(time(0));
	mine::main();
}


#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<ll,ll>
	#define PB push_back
	#define vc vector
	void chmax(int &x,const int y) {x=x>y?x:y;}
	void chmin(int &x,const int y) {x=x<y?x:y;}
	const int MAX_N=5e3+10;
	const ll MOD=998244353;
	void add(ll &x,ll y){x+=y;if(x>=MOD) x-=MOD;if(x<=-MOD) x+=MOD;}
	ll qpower(ll x,ll e)
	{
		ll ans=1;x%=MOD;
		while(e)
		{
			if(e&1) ans=ans*x%MOD;
			x=x*x%MOD;e>>=1;
		}
		return ans;
	}
	ll inv2(ll x){return qpower(x,MOD-2);}

	int hou[MAX_N*2];
	struct Edge{int y,c,g;}e[MAX_N*10];
	int ln;int oth(int x){return x&1?x+1:x-1;}
	void ins(int x,int y)
	{
		e[++ln]=(Edge){y,1,hou[x]};hou[x]=ln;
		e[++ln]=(Edge){x,0,hou[y]};hou[y]=ln;
	}
	int st,ed;
	int h[MAX_N*2],cur[MAX_N*2];queue<int> q;
	bool bfs()
	{
		memset(cur,0,sizeof cur);
		memset(h,0,sizeof h);
		h[st]=1;q.push(st);
		while(q.size())
		{
			int x=q.front();q.pop();
			for(int k=hou[x];k>0;k=e[k].g)
			{
				int y=e[k].y;
				if(h[y]==0 and e[k].c>0) h[y]=h[x]+1,q.push(y);
			}
		}
		return h[ed]>0;
	}
	int dfs(int x,int ff)
	{
		if(x==ed) return ff;
		int flow=0;
		for(int k=cur[x];k>0;k=e[k].g)
		{
			int y=e[k].y;
			if(h[y]==h[x]+1 and e[k].c>0)
			{
				int out=dfs(y,min(e[k].c,ff-flow));
				e[k].c-=out;e[oth(k)].c+=out;flow+=out;
			}
			if(flow==ff) break;
		}
		if(ff==0) h[x]=0;
		return flow;
	}
	int now=0;
	void update()
	{
		while(bfs()) now+=dfs(st,INF);
	}

	pr a[MAX_N];int ban[MAX_N];bool vis[MAX_N];
	int ans[MAX_N];
	void main()
	{
		int n=qread(),m=qread();st=5000+m+2;ed=5000+m+1;
		for(int i=1;i<=n;i++) a[i].FR=qread();
		for(int i=1;i<=n;i++) a[i].SE=qread();
		int dd=qread();for(int i=1;i<=dd;i++) ban[i]=qread(),vis[ban[i]]=1;
		for(int i=1;i<=m;i++) ins(5000+i,ed);
		for(int i=1;i<=n;i++) if(!vis[i]) ins(a[i].FR,5000+a[i].SE);

		int wt=0;ins(st,wt);
		for(int i=dd;i>=1;i--)
		{
			update();
			while(now==wt+1) wt++,ins(st,wt),update()/*,printf("i=%d wt=%d\n",i,wt)*/;
			ans[i]=wt;
			int x=ban[i];ins(a[x].FR,5000+a[x].SE);
		}
		for(int i=1;i<=dd;i++) write2(ans[i]);
	}
};
signed main()
{
	srand(time(0));
	mine::main();
}


#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]);
	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);
		cek[i] = 0;
	}
	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;
}