#include using namespace std; #define rep(i,a,b) for(int i=a;i=b;i--) typedef vector vi; typedef pair pii; int main() { int N, K; cin >> N >> K; vi B(N); rep(i, 0, N) B[i] = i; rep(k, 0, K) { int x, y; cin >> x >> y; x--; y--; swap(B[x], B[y]); } vi A(N); rep(i, 0, N) { int a; cin >> a; a--; A[a] = i; } vector ans; //rep(i, 0, N) cout << B[i] << " "; cout << endl; rep(i, 0, N) { int index = 0; rep(j, i, N) if (A[i] == B[j]) index = j; rrep(j, index, i + 1) { ans.push_back(pii(j-1, j)); swap(B[j-1], B[j]); } //rep(i, 0, N) cout << B[i] << " "; cout << endl; } cout << ans.size() << endl; for (pii p : ans) cout << (p.first+1) << " " << (p.second+1) << endl; }