    #include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define sz(v)  v.size()


void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}



int main() {
    fast();
    ll n;
    cin>>n;
    vector<int>v;
    int A[n];
    int B[n];
    int cnt1=0;
    int cnt2=0;
    int cnt=0;
    for (int j = 0; j <n ; ++j) {
        cin>>A[j];
    }
    for (int j = 0; j <n ; ++j) {
        cin>>B[j];
    }
    for (int i = 1; i <=n ; ++i) {
        v.push_back(i);
    }

    do{
        cnt++;
        bool a=true;
        bool b=true;
        for (int i = 0; i <n ; ++i) {
            if(v[i]!=A[i])a=false;
            if(v[i]!=B[i])b=false;
        }
        if(a)cnt1=cnt;
        if(b)cnt2=cnt;
        if(a&&b)break;
    }while(next_permutation(all(v)));
    cout<<abs(cnt1-cnt2);
}
