#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; while (0 < K--) { int x, y; cin >> x >> y; x--; y--; swap(B[x], B[y]); } vi A(N); rep(i, 0, N) cin >> A[i]; rep(i, 0, N) A[i]--; vector ans; 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]); } } cout << ans.size() << endl; for (pii p : ans) cout << p.first << " " << p.second << endl; }