#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
#define mp make_pair
typedef long long ll;
using namespace std;

template <typename T>
inline void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
// end of template

int main() {
    cin.tie(0);
    // source code
    int N, K;
    cin >> N >> K;
    vector<int> X(K), A(N), B(N);
    rep(i, N){
        B[i] = i + 1;
    }
    rep(i, K){
        int y;
        cin >> X[i] >> y;
        swap(B[X[i] - 1], B[y - 1]);
    }
    rep(i, N){
        int j;
        cin >> j;
        A[j - 1] = i + 1;
    }
    
    vector<int> ret;
    
    rep(i, N){
        int now = A[i];
        int j = 0;
        while (j < N) {
            if (B[j] == now) {
                break;
            }
            j++;
        }
        for (int k = j; k >= i + 1; k--) {
            swap(B[k], B[k - 1]);
            ret.push_back(k);
        }
    }
    
    cout << ret.size() << endl;
    rep(i, ret.size()){
        cout << ret[i] << " " << ret[i] + 1 << endl;
    }
    
    
    return 0;
}