#include<bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define mp make_pair
#define pb push_back
#define fp first
#define sp second
typedef long long int ll;
typedef pair<ll,ll> pp;
#define check(x, i) ((x>>i)&1LL)
#define set(x,i) (x|(1LL<<i))
#define unset(x,i) (x&~(1LL<<i))
#define INF LONG_MAX
#define MAX_N 20
#define MAX 200005
#define mod 1000000007
#define REP(i,n) for(i=0;i<n;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define len(i,s) for(i=0;s[i];i++)
#define T() ll t;cin>>t;while(t--)
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
ll gcd (ll a, ll b){return (a?gcd(b%a,a):b);}
ll pow1(ll a,ll b,ll MOD){ll ans=1;while(b!=0){if(b&1)ans=(ans*a)%MOD;a=(a*a)%MOD;b=b/2;}return ans;}
ll modInverse(ll a,ll p){return pow1(a,p-2,p);}
void ash(){
	boost 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);    
    freopen("output.txt", "w", stdout); 
#endif 
} 
 

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

int main()
{
	ash();
	ll n;
	cin>>n;
	cout<<n-1<<"\n";

}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;

struct Person {
    int val, id, ok, nxt;
}a[maxn], q[maxn];

struct D {
    int a, b;
};

int n, fflag, ansflag = 1;
int b[maxn], p[maxn];
vector<D> ans;

int cmp(const Person &a, const Person &b) {
    return a.val > b.val;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i].val);
        a[i].id = i;
    }
    for (int i = 1; i <= n; i++) scanf("%d", b + i);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i].nxt);
        if (a[i].val <= b[a[i].nxt] && a[i].nxt != i)
            fflag = 1;
        if (a[i].nxt != i)
            ansflag = 0;
        else
            a[i].ok = 1;
    }

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

    if (fflag) {
        printf("-1\n");
        return 0;
    }

    for (int i = 1; i <= n; i++) q[i] = a[i];
    sort(a + 1, a + n + 1, cmp);

    for (int i = 1; i <= n; i++) {
        if (!q[a[i].id].ok) {
            while (a[i].nxt != a[i].id) {
                ans.push_back((D){a[i].id, a[i].nxt});
                q[a[i].nxt].ok = 1;
                a[i].nxt = q[a[i].nxt].nxt;
            }
            a[i].ok = 1;
        }
    }

    cout << ans.size() << endl;
    for (const auto &i : ans) {
        printf("%d %d\n", i.a, i.b);
    }
    return 0;
}