#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n,k;
	int cnt=0;
	cin >>n>>k;
	vector<int> x,y;
	for(int i=0;i<k;i++){
		int a,b;
		cin>>a>>b;
		x.push_back(a);
		y.push_back(b);
	}
	vector<int> posi;
	posi.resize(n);
	vector<int> vgoal;
	vgoal.resize(n);
	vector<int> goal;
	for(int i=0;i<n;i++){
		int goal;
		cin>>goal;

		vgoal[goal-1]=i+1;

		int pos=i;
		for(int j=0;j<k;j++){
			if(x[j]==pos+1){
				pos++;
			}else if(y[j]==pos+1){
				pos--;
			}
		}
		posi[pos]=i+1;
	}

	for(int i=0;i<n;i++){
			int d;
			d=distance(posi.begin(),find(posi.begin(),posi.end(),vgoal[i]));

		while(vgoal[i]!=posi[i]){	
			swap(posi[d],posi[d-1]);
			y.push_back(d+1);
			x.push_back(d);
			cnt++;
			d--;
		}
	}

	cout<<cnt<<endl;
	for(int i=k;i<k+cnt;i++){
		cout<<x[i]<<" "<<y[i]<<endl;
	}

	return 0;
}