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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

#define mp make_pair
#define fr first
#define sc second

void solve() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), P(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    for (int i = 0; i < N; i++) {
        if (P[i] != i && A[i] <= B[P[i]]) {
            cout << -1 << '\n';
            return;
        }
    }
    vector<int> pos(N);
    for (int i = 0; i < N; i++) {
        pos[P[i]] = i;
    }
    vector<pii> ord(N);
    for (int i = 0; i < N; i++) {
        ord[i] = mp(A[i], i);
    }
    vector<pii> ans;
    sort(ord.begin(), ord.end());
    for (auto [w, i] : ord) {
        if (P[i] == i) {
            continue;
        }
        int p1 = pos[i], p2 = i;
        ans.emplace_back(p1, p2);
        swap(pos[P[p1]], pos[P[p2]]);
        swap(P[p1], P[p2]);
    }
    cout << ans.size() << '\n';
    for (auto [a, b] : ans) {
        cout << a + 1 << ' ' << b + 1 << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

/* 	author : sgupta_2001 	*/

#include<bits/stdc++.h>

using namespace std;

using db = double;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

//containers
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend() 
#define sor(x) sort(all(x)) 
#define rsz resize
#define ins insert 
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back 
#define pf push_front

//pairs
#define mp make_pair
#define ff first
#define ss second

//loops
#define rep(i, a, b) for(int i = a; i < b; ++i)
#define per(i, a, b) for(int i = b - 1; i >= a; --i)
#define each(x, a) for(auto &x : a)

//popular constants
const int mod = 1e9 + 7; //998244353;
const ll inf = 1e18;
const ld pie = acos((ld) - 1);

//grid problems
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//modulo operations
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

#ifdef SGUPTA_2001
#define deb(x) cerr<< #x <<" "; __print(x); cerr<<'\n';
#else
#define deb(x);
#endif

//debug containers
template<class T> void __print(T x) {cerr<<x;}
template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";}
template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; }
template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";}
template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";}
template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<typename... T> void read(T&... args) { ((cin>>args),...);}
template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';}

const int MAXN = 2002;

vector<int> gr[MAXN];
int t_in[MAXN], t_out[MAXN];
int vis[MAXN];
int timer;

void dfs(int u, int par) {

	t_in[u] = ++timer;

	vis[u] = 1;

	for(auto x : gr[u]) {
		if(x != par && !vis[x]) {
			dfs(x, u);
		}
	}

	t_out[u] = timer;
	return;
}

void solve() {

	int N, M;
	scanf("%d%d", &N, &M);

	rep(i, 0, M) {
		int X, Y;
		scanf("%d%d", &X, &Y);

		X--;Y--;

		gr[X].pb(Y);
	}

	ll ans = 0;

	rep(i, 0, N) {
		dfs(i, -1);
		
		int p = t_in[i], q = t_out[i];

		rep(j, 0, N) {
			if(p <= t_in[j] && q >= t_out[j]) {
				ans++;
			}
		}	

		fill(vis, vis + N + 1, 0);
		fill(t_in, t_in + N + 1, 0);
		fill(t_out, t_out + N + 1, 0);
		timer = 0;
	}
	
	printf("%lld\n", ans);

	return;
}


int main() {

	#ifdef SGUPTA_2001
		freopen("input.txt", "r", stdin);
		freopen("error.txt", "w", stderr);
	#endif

	auto start = std::chrono::high_resolution_clock::now();

	int t;
	t=1;
	while(t--) solve();

  auto stop = std::chrono::high_resolution_clock::now(); 
  auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
  // cerr << "Time taken : " << ((long double)duration.count())/((long double) 1e9) <<"s "<< '\n';

	 /* 
	 		STUFF TO LOOK:	
			1. Check the constraints
			2. Corner cases(n == 0 || n == 1)
			3. Variables in loops
			4. Make sure two ints aren’t multiplied to get a long long 
	*/  

	return 0;
}
