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

int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n; cin >> n;
int x[n], y[n], z[n];
for ( int i = 0; i < n; i++ ){
    cin >> x[i];
}

for ( int j = 0; j < n; j++ ){
    cin >> y[j];
}
bool p1 = true; bool p2 = true;
for ( int l = 0; l < n; l++ ){
    cin >> z[l];
    if ( z[l] != l ){
        p1 = false;
    }
    if( l!=0 ){
        if ( z[l-1] != z[l] ){
            p2 = false;
        }
    }
}
ll br = 0;
if( p1 == true){
for ( int i = 0; i < n; i++ ){
    for ( int j = 0; j < n; j++ ){
        if ( x[i] == y[j] ){
            br++;
        }
    }
}
cout << br;
}
if ( p2 == true ){
    ll k = z[0] - 1
    for( int i = 0; i < n; i++ ){
        if ( x[i] == y[k] ){
            br++;
        }  
    }
}

return 0;
}