stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <cstdio>

#include <iostream>

#include <cstring>

#include <algorithm> 

#include <vector>

#include <map>

#define N 100010

using namespace std;

vector<int>Q[N];

map<int,int>d;

bool vis[N];

int n,a[N],b[N],x[N],y[N],cnt,ans;

void dfs(int x){

    vis[x]=1;

    for (int i=0;i<Q[x].size();i++) if (!vis[Q[x][i]]) dfs(Q[x][i]);

}

int main(){

    scanf("%d",&n);



    for(int i=1;i<=n;i++){

        scanf("%d",&a[i]),a[n+1]^=a[i];

        if(!d[a[i]]) d[a[i]]=++cnt;

    }



    if(!d[a[n+1]]) d[a[n+1]]=++cnt;



    for(int i=1;i<=n;i++){

        scanf("%d",&b[i]),b[n+1]^=b[i];

        if(!d[b[i]]) d[b[i]]=++cnt;

    }



    if(!d[b[n+1]]) d[b[n+1]]=++cnt;



    memcpy(x,a,sizeof x),memcpy(y,b,sizeof y);



    sort(x+1,x+n+2),sort(y+1,y+n+2);



    for(int i=1;i<=n;i++) if(x[i]!=y[i]) {printf("-1");return 0;}



    for(int i=1;i<=n+1;i++) a[i]=d[a[i]],b[i]=d[b[i]];



    for(int i=1;i<=n;i++) if(a[i]!=b[i]) ans++,Q[a[i]].push_back(b[i]);



    if(a[n+1]!=b[n+1]) Q[a[n+1]].push_back(b[n+1]);



    for(int i=1;i<cnt;i++) if(Q[i].size()&&!vis[i]) dfs(i),ans++;



    if(!vis[cnt]) ans++;



    printf("%d",ans-1);



	return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<map>

using namespace std;

int n,ch[1000005],sh[1000005],ans,sum,fa[1000005],tot,mk[1000005];

map <int,int> mp,mmp;

int gf(int p){

	if(fa[p]==p)return p;

	return fa[p]=gf(fa[p]);

}

void mg(int a,int b){

	int fx=gf(a),fy=gf(b);

	if(fx!=fy){

		fa[fx]=fy;

	}

}

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		scanf("%d",&sh[i]);sum^=sh[i];mp[sh[i]]++;

	}mp[sum]++;

	for(int i=1;i<=n;i++){

		scanf("%d",&ch[i]);mp[ch[i]]--;

		if(mp[ch[i]]<0){

			ans=-999999999;

		}

		if(sh[i]!=ch[i]){mk[i]=1;

			ans++;

		}

	}

	sh[n+1]=sum;

	for(int i=1;i<=n+1;i++){

		if(mp[sh[i]]>0){

			ch[n+1]=sh[i];break;

		}

	}

	n++;tot=n+n;

	mk[n]=1;

	for(int i=1;i<=n;i++){

		if(!mk[i])continue;

		if(mmp[sh[i]]==0)mmp[sh[i]]=++tot;

		fa[i]=i;fa[i+n]=i+n;

	}

	for(int i=1;i<=tot;i++)fa[i]=i;

	for(int i=1;i<=n;i++){

		if(!mk[i]){

			fa[i]=fa[i+n]=0;

		}

	}

	for(int i=1;i<=n;i++){

		if(sh[i]!=ch[i])mg(i,i+n);

		mg(i,mmp[sh[i]]);mg(i+n,mmp[ch[i]]);

	}

	for(int i=1;i<=tot;i++){

		if(fa[i]==i){//printf("i:%d\n",i);

			ans++;

		}

	}

	ans--;

	if(ans<0)printf("-1");

	else printf("%d",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <iostream>

#include <cstring>

#include <algorithm> 

#include <vector>

#include <map>

using namespace std;

#define Max(a,b) ((a)>(b)?(a):(b))

#define Min(a,b) ((a)<(b)?(a):(b))

#define ll long long 

#define ri register int

#define f(i,a,b) for(ri i=a;i<=b;i++)

#define rf(i,b,a) for(ri i=b;i>=a;i--)

const int N=1e5+10;

int n,cnt,ans;

int a[N],b[N],x[N],y[N];

bool vis[N];

vector<int>Q[N];

map<int,int>d;

inline void read(int &x) {

    x=0;int f=1;char c=getchar();

    while (c>'9'||c<'0') {if (c=='-') f=-1;c=getchar();}

    while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}

    x*=f;

}

void dfs(int x)

{

    vis[x]=1;

    for (int i=0;i<Q[x].size();i++) 

    	if (!vis[Q[x][i]]) dfs(Q[x][i]);

}

int main()

{

   	read(n);

    for (int i=1;i<=n;i++) {

        read(a[i]),a[n+1]^=a[i];

        if (!d[a[i]]) d[a[i]]=++cnt;

    }

    if (!d[a[n+1]]) d[a[n+1]]=++cnt;

    for (int i=1;i<=n;i++) {

        read(b[i]),b[n+1]^=b[i];

        if (!d[b[i]]) d[b[i]]=++cnt;

    }

    if (!d[b[n+1]]) d[b[n+1]]=++cnt;

    memcpy(x,a,sizeof x),memcpy(y,b,sizeof y);

    sort(x+1,x+n+2),sort(y+1,y+n+2);

    for (int i=1;i<=n;i++) 

    	if (x[i]!=y[i]) {printf("-1");return 0;}

    for (int i=1;i<=n+1;i++) 

    	a[i]=d[a[i]],b[i]=d[b[i]];

    for (int i=1;i<=n;i++) 

    	if (a[i]!=b[i]) ans++,Q[a[i]].push_back(b[i]);

    if (a[n+1]!=b[n+1]) Q[a[n+1]].push_back(b[n+1]);

    for (int i=1;i<cnt;i++) 

    	if (Q[i].size()&&!vis[i]) dfs(i),ans++;

    if (!vis[cnt]) ans++;

    printf("%d",ans-1);

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<map>

using namespace std;

int n,ch[1000005],sh[1000005],ans,sum,fa[1000005],tot,mk[1000005];

map <int,int> mp,mmp;

int gf(int p){

	if(fa[p]==p)return p;

	return fa[p]=gf(fa[p]);

}

void mg(int a,int b){

	int fx=gf(a),fy=gf(b);

	if(fx!=fy){

		fa[fx]=fy;

	}

}

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		scanf("%d",&sh[i]);sum^=sh[i];mp[sh[i]]++;

	}mp[sum]++;

	for(int i=1;i<=n;i++){

		scanf("%d",&ch[i]);mp[ch[i]]--;

		if(mp[ch[i]]<0){

			ans=-999999999;

		}

		if(sh[i]!=ch[i]){mk[i]=1;

			ans++;

		}

	}

	sh[n+1]=sum;

	for(int i=1;i<=n+1;i++){

		if(mp[sh[i]]>0){

			ch[n+1]=sh[i];break;

		}

	}

	n++;tot=n+n;

	mk[n]=1;

	for(int i=1;i<=n;i++){

		if(!mk[i])continue;

		if(mmp[sh[i]]==0)mmp[sh[i]]=++tot;

		fa[i]=i;fa[i+n]=i+n;

	}

	for(int i=1;i<=tot;i++)fa[i]=i;

	for(int i=1;i<=n;i++){

		if(!mk[i]){

			fa[i]=fa[i+n]=0;

		}

	}

	for(int i=1;i<=n;i++){

		if(sh[i]!=ch[i])mg(i,i+n);

		mg(i,mmp[sh[i]]);mg(i+n,mmp[ch[i]]);

	}

	for(int i=1;i<=tot;i++){

		if(fa[i]==i){//printf("i:%d\n",i);

			ans++;

		}

	}

	ans--;

	if(ans<0)printf("-1");

	else printf("%d",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define maxn 100010

#define pb push_back

using namespace std;



int a[maxn],b[maxn],c[maxn],d[maxn],fa[maxn],sz[maxn],n,cnt=0,cnt2=0;

bool vis[maxn];

vector<int> v;

int find(int x){

	return fa[x]==x?x:fa[x]=find(fa[x]);

}

int main(){

	ios::sync_with_stdio(0);

	cin>>n;

	for(int i=1;i<=n;i++)

		cin>>a[i],a[n+1]^=a[i],v.pb(a[i]);

	v.pb(a[n+1]);

	for(int i=1;i<=n;i++)

		cin>>b[i],b[n+1]^=b[i];

	memcpy(c,a,sizeof(a));

	memcpy(d,b,sizeof(b));

	sort(c+1,c+n+2),sort(d+1,d+n+2);

	for(int i=1;i<=n+1;i++){

		if(c[i]!=d[i])

			return cout<<"-1"<<endl,0;

	}

	sort(v.begin(),v.end());

	v.erase(unique(v.begin(),v.end()),v.end());

	for(int i=0;i<v.size();i++)

		fa[i]=i,sz[i]=1;

	for(int i=1;i<=n+1;i++){

		int x=lower_bound(v.begin(),v.end(),a[i])-v.begin();

		int y=lower_bound(v.begin(),v.end(),b[i])-v.begin();

		if(a[i]!=b[i]||i==n+1)

			cnt+=i<=n,vis[x]=vis[y]=1;

		if(find(x)!=find(y))

			fa[find(x)]=find(y);

	}

	if(!cnt)

		return cout<<"0"<<endl,0;

	for(int i=0;i<v.size();i++)

		cnt+=vis[i]&&find(i)==i;

	cout<<cnt-1<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<map>

using namespace std;

int n,ch[1000005],sh[1000005],ans,sum,fa[1000005],tot,mk[1000005];

map <int,int> mp,mmp;

int gf(int p){

	if(fa[p]==p)return p;

	return fa[p]=gf(fa[p]);

}

void mg(int a,int b){

	int fx=gf(a),fy=gf(b);

	if(fx!=fy){

		fa[fx]=fy;

	}

}

int main(){

//	freopen("duliu.in","r",stdin);

//	freopen("duliu.out","w",stdout);

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		scanf("%d",&sh[i]);sum^=sh[i];mp[sh[i]]++;

	}mp[sum]++;

	for(int i=1;i<=n;i++){

		scanf("%d",&ch[i]);mp[ch[i]]--;

		if(mp[ch[i]]<0){

			ans=-999999999;

		}

		if(sh[i]!=ch[i]){mk[i]=1;

			ans++;

		}

	}

	sh[n+1]=sum;

	for(int i=1;i<=n+1;i++){

		if(mp[sh[i]]>0){

			ch[n+1]=sh[i];break;

		}

	}

	n++;tot=n+n;

	mk[n]=1;

	for(int i=1;i<=n;i++){

		if(!mk[i])continue;

		if(mmp[sh[i]]==0)mmp[sh[i]]=++tot;

		fa[i]=i;fa[i+n]=i+n;

	}

	for(int i=1;i<=tot;i++)fa[i]=i;

	for(int i=1;i<=n;i++){

		if(!mk[i]){

			fa[i]=fa[i+n]=0;

		}

	}

	for(int i=1;i<=n;i++){

		if(sh[i]!=ch[i])mg(i,i+n);

		mg(i,mmp[sh[i]]);mg(i+n,mmp[ch[i]]);

	}

	for(int i=1;i<=tot;i++){

		if(fa[i]==i){//printf("i:%d\n",i);

			ans++;

		}

	}

	ans--;

	if(ans<0)printf("-1");

	else printf("%d",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

const int MAXN = 2e5 + 10;

using namespace std;

int n;

int A[MAXN], B[MAXN], ta[MAXN], tb[MAXN], sa, sb, tot = 0, Do[MAXN], fa[MAXN];

int find(int x) {

    return fa[x] == x ? fa[x] : fa[x] = find(fa[x]);

}

int unionn(int x, int y) {

    fa[x] = y;

}

int main() {

    scanf("%d",&n);

    for(int i = 1; i <= n; i++)scanf("%d",&A[i]),sa ^= A[i]; A[n + 1] = sa;

    for(int i = 1; i <= n; i++)scanf("%d",&B[i]),sb ^= B[i]; B[n + 1] = sb;

    n++;

    memcpy(ta, A, sizeof(A)); memcpy(tb, B, sizeof(B));

    sort(ta + 1, ta + n + 1); sort(tb + 1, tb + n + 1);

    for(int i = 1; i <n; i++) if(ta[i] != tb[i]) return puts("-1"), 0;

 

    int ans = 0, sum = 0;

    for(int i = 1; i <= n; i++) 

        if(A[i] != B[i] || (i == n)) {

            Do[++sum] = A[i]; Do[++sum] = B[i];

            if(i < n)ans++;

        }

    if(ans == 0) return puts("0"), 0;

 

    sort(Do + 1, Do + sum + 1);

    sum = unique(Do + 1, Do + sum + 1) - Do - 1;

    for(int i = 1; i <= sum; i++) fa[i] = i;

    for(int i = 1; i <= n; i++)

        if(A[i] != B[i]) {

            A[i] = lower_bound(Do + 1, Do + sum + 1, A[i]) - Do;

            B[i] = lower_bound(Do + 1, Do + sum + 1, B[i]) - Do;

            unionn(find(A[i]), find(B[i]));

        }

 

    for(int i = 1; i <= sum; i++)

        if(fa[i] == i) ans++;

    printf("%d", ans - 1);

 

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

int S[100005],T[100005],n,ans,sum;

int A[100005],B[100005],sa,sb;

int fa[100005],Do[200005];

int gg(){printf("-1");return 0;}

int ask(int x){if(fa[x]==x)return x;return fa[x]=ask(fa[x]);}

void unite(int x,int y){fa[x]=y;}

int main(){

//  freopen("duliu.in","r",stdin);

//  freopen("duliu.out","w",stdout);

    scanf("%d",&n);

    for(int i=1;i<=n;i++)scanf("%d",&A[i]),sa^=A[i];A[n+1]=sa;

    for(int i=1;i<=n;i++)scanf("%d",&B[i]),sb^=B[i];B[n+1]=sb;

    memcpy(S,A,sizeof A);memcpy(T,B,sizeof B);

    n++;sort(S+1,S+1+n);sort(T+1,T+1+n);

    for(int i=1;i<n;i++)if(S[i]!=T[i])return gg();

    for(int i=1;i<=n;i++)

    	if(A[i]!=B[i]||(i==n)){

			Do[++sum]=A[i];

			Do[++sum]=B[i];

			if(i<n)ans++;

		}

	if(ans==0)return printf("0"),0;

	sort(Do+1,Do+1+sum);

	sum=unique(Do+1,Do+sum+1)-Do-1;

	for(int i=1;i<=sum;i++)fa[i]=i;

	for(int i=1;i<=n;i++){

		if(A[i]!=B[i]){

			A[i]=lower_bound(Do+1,Do+1+sum,A[i])-Do;

			B[i]=lower_bound(Do+1,Do+1+sum,B[i])-Do;

			unite(ask(A[i]),ask(B[i]));

		}

	}

	for(int i=1;i<=sum;i++)ans+=(fa[i]==i);

	printf("%d",ans-1);

}

/*

3

1 2 3

1 3 2

*/

/*

4

1 4 2 6

1 2 4 6

*/

/*

10

1 3 3 9 4 5 1 6 4 0

4 1 3 9 10 4 3 1 6 5

*/

/*

5

1 2 4 8 0

2 1 15 8 4

*/

/*

10

1 2 3 4 4 5 6 7 8 12

2 1 4 3 4 0 5 6 7 8

*/

/*

10

1 2 3 4 5 6 7 8 9 10

10 1 2 3 4 5 6 7 8 9

*/

/*

10

1 2 3 4 5 6 7 8 9 10

2 1 4 3 6 5 8 7 10 9

*/

/*

9

1 2 3 4 5 6 7 8 9

9 1 2 3 4 5 6 7 8

*/

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

const int MAXN = 2e5 + 10;

using namespace std;

int n;

int ans=0,sum=0;

int A[MAXN], B[MAXN], ta[MAXN], tb[MAXN], sa, sb, tot = 0, Do[MAXN], fa[MAXN];

int find(int x) {

    return fa[x] == x ? fa[x] : fa[x] = find(fa[x]);

}

int unionn(int x, int y) {

    fa[x] = y;

}

int main() {

    scanf("%d",&n);

    for(int i=1;i<=n;i++)scanf("%d",&A[i]),sa^=A[i];A[n+1]=sa;

    for(int i=1;i<=n;i++)scanf("%d",&B[i]),sb^=B[i];B[n+1]=sb;

    memcpy(ta,A,sizeof(A));memcpy(tb,B,sizeof(B));

    n++;sort(ta+1,ta+n+1);sort(tb+1,tb+n+1);

    for(int i=1;i<n;i++)if(ta[i]!=tb[i])return puts("-1"), 0;

    for(int i=1;i<=n;i++)

        if(A[i]!=B[i]||(i==n)){

            Do[++sum]=A[i]; 

			Do[++sum]=B[i];

            if(i<n)ans++;

        }

    if(ans==0)return puts("0"), 0;

    sort(Do+1,Do+sum+1);

    sum=unique(Do+1,Do+sum+1)-Do-1;

    for(int i=1;i<=sum;i++)fa[i]=i;

    for(int i=1;i<=n;i++)

        if(A[i]!=B[i]) {

            A[i]=lower_bound(Do+1,Do+sum+1,A[i])-Do;

            B[i]=lower_bound(Do+1,Do+sum+1,B[i])-Do;

            unionn(find(A[i]),find(B[i]));

        }

    for(int i=1;i<=sum;i++)ans+=(fa[i]==i);

    printf("%d", ans - 1);

 

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

int S[100005],T[100005],n,ans,sum;

int A[100005],B[100005],sa,sb;

int fa[100005],Do[200005];

int gg(){printf("-1");return 0;}

int ask(int x){if(fa[x]==x)return x;return fa[x]=ask(fa[x]);}

void unite(int x,int y){fa[x]=y;}

int main(){

//  freopen("duliu.in","r",stdin);

//  freopen("duliu.out","w",stdout);

    scanf("%d",&n);

    for(int i=1;i<=n;i++)scanf("%d",&A[i]),sa^=A[i];A[n+1]=sa;

    for(int i=1;i<=n;i++)scanf("%d",&B[i]),sb^=B[i];B[n+1]=sb;

    memcpy(S,A,sizeof A);memcpy(T,B,sizeof B);

    n++;sort(S+1,S+1+n);sort(T+1,T+1+n);

    for(int i=1;i<n;i++)if(S[i]!=T[i])return gg();

    for(int i=1;i<=n;i++)

    	if(A[i]!=B[i]||(i==n)){

			Do[++sum]=A[i];

			Do[++sum]=B[i];

			if(i<n)ans++;

		}

	if(ans==0)return printf("0"),0;

	sort(Do+1,Do+1+sum);

	sum=unique(Do+1,Do+sum+1)-Do-1;

	for(int i=1;i<=sum;i++)fa[i]=i;

	for(int i=1;i<=n;i++){

		if(A[i]!=B[i]){

			A[i]=lower_bound(Do+1,Do+1+sum,A[i])-Do;

			B[i]=lower_bound(Do+1,Do+1+sum,B[i])-Do;

			unite(ask(A[i]),ask(B[i]));

		}

	}

	for(int i=1;i<=sum;i++)ans+=(fa[i]==i);

	printf("%d",ans-1);

}

/*

3

1 2 3

1 3 2

*/

/*

4

1 4 2 6

1 2 4 6

*/

/*

10

1 3 3 9 4 5 1 6 4 0

4 1 3 9 10 4 3 1 6 5

*/

/*

5

1 2 4 8 0

2 1 15 8 4

*/

/*

10

1 2 3 4 4 5 6 7 8 12

2 1 4 3 4 0 5 6 7 8

*/

/*

10

1 2 3 4 5 6 7 8 9 10

10 1 2 3 4 5 6 7 8 9

*/

/*

10

1 2 3 4 5 6 7 8 9 10

2 1 4 3 6 5 8 7 10 9

*/

/*

9

1 2 3 4 5 6 7 8 9

9 1 2 3 4 5 6 7 8

*/

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define ll long long

#define fr(i,x,y) for(int i=x;i<=y;i++)

#define rf(i,x,y) for(int i=x;i>=y;i--)

using namespace std;

const int N=100002;

int n;

struct data{

	int x,y;

}a[N];

map<int,int> mp;

int f[N],sz[N];

vector<int> w[N];

int b[N];



void read(int &x){

	char ch=getchar();x=0;

	for(;ch<'0'||ch>'9';ch=getchar());

	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';

}



int gf(int x){

	return f[x]==x?x:f[x]=gf(f[x]);

}



void unio(int x,int y){

	int fx=gf(x),fy=gf(y);

	if (fx!=fy){

		f[fx]=fy;

		sz[fy]+=sz[fx];

	}

}



int main(){

	read(n);

	int xr=0;

	fr(i,1,n) read(a[i].x),xr^=a[i].x,mp[a[i].x]++;

	a[n+1].x=xr;mp[xr]++;

	int tot=0;

	/*for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)

	 it->second=++tot;*/

	int flag=0;

	fr(i,1,n){

		read(a[i].y);

		if (!mp.count(a[i].y)){

			printf("-1\n");

			return 0;

		}

		mp[a[i].y]--;

		if (mp[a[i].y]==0) mp.erase(a[i].y);

		if (a[i].y==xr&&a[i].x!=a[i].y) flag=1;

	}

	a[n+1].y=mp.begin()->first;

	

	//sort(a+1,a+1+n,cmp)

	mp.clear();

	fr(i,1,n+1) if (a[i].x!=a[i].y) mp[a[i].x]=1,mp[a[i].y]=1;

	tot=0;

	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)

	 it->second=++tot;

	fr(i,1,n+1) if (a[i].x!=a[i].y) a[i].x=mp[a[i].x],a[i].y=mp[a[i].y];

	//fr(i,1,n+1) if (a[i].x!=a[i].y) w[a[i].y].push_back(i);

	fr(i,1,tot) f[i]=i;

	fr(i,1,n+1) if (a[i].x!=a[i].y) sz[a[i].x]++;

	fr(i,1,n+1)

	 if (a[i].x!=a[i].y){

	 	//b[a[i].x]=1;

		unio(a[i].x,a[i].y);

	 } 

	int ans=0;

	fr(i,1,tot) if (gf(i)==i) ans+=sz[i]+1;

	if (ans==0){

		printf("0\n");

		return 0;

	}

	//cout<<ans<<endl;

	if (flag) ans-=2;

	if (flag&&a[n+1].x==a[n+1].y) ans++;

	cout<<ans<<endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<map>

#define maxn 100005

using namespace std;

int n,a[maxn],b[maxn],fa[maxn],siz[maxn],cnt,ans;

map<int,int> mp,val;

int find(int x)

{

	if(fa[x]==x) return x;

	return fa[x]=find(fa[x]);

}

int main()

{

	scanf("%d",&n);

	int x=0;

	for(int i=1;i<=n;i++)

	{

		scanf("%d",&a[i]);

		mp[a[i]]++; x^=a[i];

		if(!val[a[i]]) val[a[i]]=++cnt;

	}

	mp[x]++;

	for(int i=1;i<=n;i++)

	{

		scanf("%d",&b[i]);

		if(!mp[b[i]]) { printf("-1\n"); return 0; }

		mp[b[i]]--;

		if(!val[b[i]]) val[b[i]]=++cnt;

	}

	for(int i=1;i<=cnt;i++) fa[i]=i,siz[i]=1;

	for(int i=1;i<=n;i++)

		if(a[i]!=b[i])

		{

			int r1=find(val[a[i]]),r2=find(val[b[i]]);

			if(r1!=r2) fa[r1]=r2,siz[r2]+=siz[r1];

			ans++;

		}

	bool f=true;

	for(int i=1;i<=n;i++)

		if(a[i]!=b[i]) { f=false; break; }

	if(f) { printf("0\n"); return 0; }

	if(!val[x]) ans++;

	for(int i=1;i<=cnt;i++)

		if(find(i)==i&&siz[i]>1) ans++;

	printf("%d\n",ans-1);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<stdio.h>

#include<algorithm>

#include<string.h>

#include<math.h>

#include<stdlib.h>

#include<bitset>

#include<map>

#include<queue>

#include<vector>

#include<set>

#include<iostream>

#include<string>

#define ll long long

#define N 505

#define For(i,x,y) for(int i=x;i<=y;i++)

#define Rep(i,x,y) for(int i=x;i>=y;i--)

#define Forn(i,x,y) for(int i=x;i<y;i++)

using namespace std;

int read(){int x=0,f=0;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;return f?-x:x;}

void write(int x){if(x<10) putchar(x+48);else write(x/10),putchar(x%10+48);}

void writeln(int x){if(x<0) putchar('-'),x=-x;write(x);putchar('\n');}

int n,m;

char s[N][N];

int main(){

	n=read();m=read();

	For(i,1,n) scanf("%s",s[i]+1);

	For(i,1,n) if(i&1){

		For(j,1,m-1) cout<<"#";

		cout<<'.'<<endl;

	}else{

		For(j,1,m) if(s[i][j]=='#'||j==1) cout<<'#';else cout<<".";

		cout<<endl;

	}

	For(i,1,n) if(!(i&1)){

		cout<<".";

		For(j,2,m) cout<<"#";

		cout<<endl;

	}else{

		For(j,1,m) if(s[i][j]=='#'||j==m) cout<<"#";else cout<<".";

		cout<<endl;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

#define MN 505

using namespace std;

char ch[MN][MN];int n,m;bool a[MN][MN],b[MN][MN];

int main(){

	scanf("%d%d",&n,&m);

	for(int i=1;i<=n;i++)scanf("%s",ch[i]+1);

	for(int i=1;i<=n;i++)a[i][1]=b[i][m]=1;

//	for(int i=1;i<=n;i++){for(int j=1;j<=m;j++)printf("%c",a[i][j]?'#':'.');puts("");}

//	for(int i=1;i<=n;i++){for(int j=1;j<=m;j++)printf("%c",b[i][j]?'#':'.');puts("");}

	for(int i=1;i*2<=n;i++){

		for(int j=2;j<m;j++)a[i*2-1][j]=b[i*2][j]=1;

	}

	if(n%2)for(int i=2;i<m;i++)a[n][i]=1;

	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)a[i][j]|=(ch[i][j]=='#'),b[i][j]|=(ch[i][j]=='#');

	for(int i=1;i<=n;i++){for(int j=1;j<=m;j++)printf("%c",a[i][j]?'#':'.');puts("");}

	for(int i=1;i<=n;i++){for(int j=1;j<=m;j++)printf("%c",b[i][j]?'#':'.');puts("");}

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(){

	double a,b,c,d;

	cin>>a>>b>>c>>d;

	int x=ceil(a/d);

	int y=ceil(c/b);

	if(y>x)cout<<"No"<<endl;

	else cout<<"Yes"<<endl;

}

// Optimized solution to the same problem (faster):
 #include<stdio.h>

 int main()

 {

          int a,b,c,d,x,y;

          scanf("%d%d%d%d",&a,&b,&c,&d);

          x=(a+d-1)/d;

          y=(c+b-1)/b;

          if(x>=y)

                    printf("Yes\n");

          else

                    printf("No\n");

 return 0;

 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>



using namespace std;



int main()

{

    int a, b, c, d;

    int cnt1, cnt2;

    while(cin >> a >> b >> c >> d) {

        if(a%d)

            cnt1 = a/d+1;

        else

            cnt1 = a/d;

        if(c%b)

            cnt2 = c/b+1;

        else

            cnt2 = c/b;

        if(cnt1 >= cnt2)

            cout << "Yes" << endl;

        else

            cout << "No" << endl;

    }

    return 0;

}


// Optimized solution to the same problem (faster):
 #include<stdio.h>

 int main()

 {

          int a,b,c,d,x,y;

          scanf("%d%d%d%d",&a,&b,&c,&d);

          x=(a+d-1)/d;

          y=(c+b-1)/b;

          if(x>=y)

                    printf("Yes\n");

          else

                    printf("No\n");

 return 0;

 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
 #include<iostream>

 using namespace std;



 int main(){

 int A,B,C,D,X,Y;

        cin>>A>>B>>C>>D;

 X=(A+D-1)/D;

 Y=(C+B-1)/B;

                   cout<<(X>=Y?"Yes":"No")<<"\n";

 }


// Optimized solution to the same problem (faster):
 #include<stdio.h>

 int main()

 {

          int a,b,c,d,x,y;

          scanf("%d%d%d%d",&a,&b,&c,&d);

          x=(a+d-1)/d;

          y=(c+b-1)/b;

          if(x>=y)

                    printf("Yes\n");

          else

                    printf("No\n");

 return 0;

 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main()

{

  int A,B,C,D,x,y;

  cin>>A>>B>>C>>D;

  x=A/D;if(A%D>0)x++;y=C/B;if(C%B>0)y++;

  return cout<<((x>=y)?"Yes":"No")<<endl,0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main(void)

{

  int A,B,C,D,x;

  x=scanf("%d %d %d %d",&A,&B,&C,&D);

  while(x)

  {

    C-=B;if(C<=0)return printf("Yes"),0;

    A-=D;if((A<=0))return printf("No"),0;

  }

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define p_ pair<int,int>

#define mp_ make_pair

#define ll long long

#define pb push_back

#define fi first

#define se second

#define rep(i,a,b) for(int i=a;i<=b;i++)

#define show1(a) cout<<#a<<" = "<<a<<endl

#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl

using namespace std;

const ll INF = 1LL<<60;

const int inf = 1<<30;

const int maxn = 2e5+5;

inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int n,m,a[maxn];

vector<int> g[maxn];

int main()

{

    fastio();

    cin>>n>>m;

    rep(i,1,n) cin>>a[i];

    rep(i,1,m) {int u,v;cin>>u>>v;g[u].pb(v),g[v].pb(u);}

    int ans = 0;

    rep(i,1,n){

        int sz = g[i].size();

        int flag = 1;

        for(int v:g[i]) if(a[v]>=a[i]) {flag=0;break;}

        if(flag) ans++;

    }

    cout<<ans<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

const int maxn = 1e5+5;



int a[maxn];

int can[maxn];



int main()

{

    int n,m;

    scanf("%d%d",&n,&m);

    for(int i=1;i<=n;i++) {scanf("%d",&a[i]);can[i]=1;}



    for(int i=1;i<=m;i++)

    {

        int u,v;

        scanf("%d%d",&u,&v);

        if(a[u]>=a[v]) can[v] = 0;

        if(a[v]>=a[u]) can[u] = 0;

    }

    int ans = 0;

    for(int i=1;i<=n;i++) if(can[i]) ans++;

    printf("%d\n",ans);

    return 0;

}


// Fastest known solution for this problem: