/**
 *    author:  otera    
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
    int n; cin >> n;
    vector<int> a(n), b(n), p(n);
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        cin >> b[i];
    }
    vector<int> rp(n);
    rep(i, n) {
        cin >> p[i]; -- p[i];
        rp[p[i]] = i;
    }
    vector<bool> ok(n, 0);
    rep(i, n) {
        if(p[i] != i and a[i] <= b[p[i]]) {
            cout << -1 << "\n";
            return;
        }
        if(p[i] == i) ok[i] = 1;
    }
    vector<int> ids(n);
    iota(all(ids), 0);
    sort(all(ids), [&](int i, int j){ return b[i] > b[j];});
    vector<P> ans;
    auto f = [&](int i, int j) {
        ans.push_back({i, j});
        int pi = p[i], pj = p[j];
        p[i] = pj, p[j] =  pi;
        rp[pj] = i, rp[pi] = j; 
    };
    rep(i, n) {
        int id = ids[i];
        if(rp[id] == id) continue;
        f(rp[id], id);
    }
    // rep(i, n) cerr << p[i] << " \n"[i == n - 1];
    cout << (int)ans.size() << "\n";
    rep(i, (int)ans.size()) {
        cout << ans[i].fr + 1 << " " << ans[i].sc + 1 << "\n";
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define M1 1000000007
#define M2 998244353
#define INF 1e18
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<int>
#define vlli vector <long long>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)

/********************************************************************/
const double pi = 3.1415926535;
/********************************************************************/
//FAST IO//
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}


/********************************************************************/
int main()
{
  FAST();
 
ll int n,p; cin>>n>>p;
ll int ans=p-1;
ll ans2=1;

//calculate (p-2)^(n-1)
ll int x=n-1; 
ll temp=p-2;
while (x>0)
{
  if (x&1)
  {
    ans*=temp;
    ans%=M1;
  }
  temp= temp*temp;
  temp%=M1;
  x/=2;
}
cout<<ans<<endl;
 
}