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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

const int N = 2e5+10;
ll a[N], b[N], p[N];
ll dono[N];

void no(){
	cout << -1 << "\n";
	exit(0);
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	ll n; cin >> n;
	fr(i,n) cin >> a[i];
	fr(i,n) cin >> b[i];
	fr(i,n) cin >> p[i], p[i]--;
	fr(i,n) dono[p[i]] = i;
	
	
	
	fr(i,n) if(p[i]!=i and b[p[i]]>=a[i]) no();
	
	vector<pair<ll,ll>> vp;
	fr(i,n) vp.emplace_back(a[i],i);
	sort(all(vp));
	vector<pair<ll,ll>> ans;
	for(auto &[peso,ia] : vp){
		if(p[ia]==ia) continue;
		ll iq = dono[ia];
		ans.emplace_back(ia,iq);
		swap(p[ia],p[iq]);
		dono[p[ia]] = ia;
		dono[p[iq]] = iq;
	}
	cout << sz(ans) << "\n";
	for(auto &[i,j] : ans){
		cout << i+1 << " " << j+1 << "\n";
	}
}
/*
"An anomaly, I'm Muhammad Ali
  Cause I know one day I'm gonna be the"
                - Greatest, Eminem
*/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int n; cin >> n;
    vector<pair<int,int>> a(n), b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i].ff >> b[i].ff;
        a[i].ss = b[i].ss = i;
    }
    sort(all(a));
    sort(all(b));
    if(a.front().ss != b.front().ss){
        cout << max(a[0].ff , b[0].ff) << endl;
    }
    else{
        cout << min({a[0].ff + b[0].ff, max(a[1].ff ,b[0].ff), max(a[0].ff , b[1].ff)}) << endl;
    }
    return 0;
}