int n,l,r;
scanf("%d",&n);
int* a=(int*)malloc(n*sizeof(int));
int* b=(int*)malloc(n*sizeof(int));
for(int i=1;i<n;i++) {
    scanf("%d",&a[i]);
    if(a[i]>=1 && a[i]<=n)l=a[i];
}
for(int i=1;i<n;i++) {
    scanf("%d",&b[i]);
    if(b[i]>=l && b[i]<=n)r=b[i];
}
printf("%d",(a[l]^a[r])*(b[l]&&b[r]));