#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, _s) for (int i = (_s);i < (int)( n ); i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &_l, const T b) {
    if (_l < b) {
        _l = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &_l, const T b) {
    if (_l > b) {
        _l = b;
        return true;
    }
    return false;
}

# ifdef LOCAL_DEBUG
template<typename T>
void vdeb(const std::vector<T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(const std::vector<std::vector<T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
# endif

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rip(i,n,0) cin >> a[i];
    vector<int> b(n);
    rip(i,n,0) cin >> b[i];
    vector<int> p(n);
    vector<int> q(n);
    rip(i,n,0) {
        cin >> p[i];
        p[i]--;
        q[p[i]] = i;
    }
    vector<Pii> ans(0);
    MinHeap<Pii> pq;
    rip(i,n,0) {
        pq.push({a[i], i});
    }
    while(!pq.empty()) {
        auto now = pq.top(); pq.pop();
        if(p[now.second] == now.second) continue;
        if(now.first <= b[p[now.second]]) {
            cout << -1 << endl;
            return 0;
        }
        int c = q[now.second];
        ans.push_back({now.second+1, c+1});
        q[p[now.second]] = c;
        q[now.second]  = now.second;
        p[c] = p[now.second];
        p[now.second] = now.second;
    }
    cout << ans.size() << '\n';
    rip(i,ans.size(), 0) {
        cout << ans[i].first MM ans[i].second << '\n';
    }
}
#include <bits/stdc++.h>
using namespace std;

#define ll              long long int
#define scan(any)       for(auto &i:any) cin>>i;
#define print(any)      for(auto i:any) cout<<i<<" "; 
#define endl            '\n'
#define pb              push_back
#define vll             vector<ll> 
#define f(i,x,y)        for(i=x;i<y;i++)
#define INF             LLONG_MAX
#define s(x)            sort(x.begin(),x.end())
#define all(v)          v.begin(),v.end()
#define p2(n,x)         cout << fixed << setprecision(x) <<n<<endl; 
#define pll             pair<ll,ll> 
#define mll             map<ll,ll>
#define ff              first
#define ss              second
#define blt(x)          __builtin_popcount(x)

void solve()
{
    ll i,j,k,n,m;
    cin>>n>>m;
    vll v(n);
    scan(v);
    set<ll> s;
    mll mp;
    f(i,0,n+1)
    s.insert(i);

    ll ans=INF;

    ll l=0,h=0;
    while(h<n)
    {
        if(s.find(v[h])!=s.end())
            s.erase(s.find(v[h]));
        mp[v[h]]++;
        if(h-l+1==m)
        {
            ans=min(ans,*s.begin());
            if(mp[v[l]]==1)
                s.insert(v[l]);
            mp[v[l]]--;

            h++;
            l++;
        }
        else
            h++;
    }
    cout<<ans;


}

int main()
{
    

    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll t = 1;
    while(t--) {
        solve();    
    }
    return 0;
}