#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i< int (n); i++)
using namespace std;
typedef long long ll;

int main(){

vector<int> a(200100);
int n;
cin >> n;
int k=0;
for(int i=0; i<n; i++){
    int p;
    cin >> p;
    a[p]++;
    while(k<200010){
        if(a[k]==0) {
            cout << k << endl;
            break;
        }
        else k++;
    }
}

/*
for(int i=0; i<n; i++){
    for(int j=0; j<200100; j++){
        if(a[j]==0) {
            cout << a[j] << endl;
            break;
        }
    }
}
*/

}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 2e5+5;

typedef pair <int,int> pii;
#define x first
#define y second

int w[sz], b[sz], p[sz], g[sz];
bitset <sz> vis;

int main() {
   int n;
   cin >> n;
   for(int i=1; i<=n; i++) scanf("%d", &w[i]);
   for(int i=1; i<=n; i++) scanf("%d", &b[i]);
   for(int i=1; i<=n; i++) scanf("%d", &p[i]);

   for(int i=1; i<=n; i++) {
      if(p[i] == i) {
         vis[i] = 1;
         continue;
      }
      if(b[p[i]] >= w[i]) {
         puts("-1");
         exit(0);
      }
      g[p[i]] = i;
   }

   vector <pii> ans;
   for(int i=1; i<=n; i++) {
      if(vis[i]) continue;
      vector <int> now;
      int u = i;
      while(!vis[u]) {
         vis[u] = 1;
         now.push_back(u);
         u = g[u];
      }
      int smol = 0;
      for(int j=0; j<now.size(); j++) {
         int p1 = now[j], p2 = now[smol];
         if(b[p[p1]] < b[p[p2]]) smol = j;
      }
      rotate(now.begin(), now.begin()+smol, now.end());
      for(int j=1; j<now.size(); j++) ans.emplace_back(now[j-1], now[j]);
   }

   printf("%d\n", ans.size());
   for(auto &p : ans) printf("%d %d\n", p.x, p.y);
}
