#include using namespace std; namespace { typedef double real; typedef long long ll; template ostream& operator<<(ostream& os, const vector& vs) { if (vs.empty()) return os << "[]"; os << "[" << vs[0]; for (int i = 1; i < vs.size(); i++) os << " " << vs[i]; return os << "]"; } template istream& operator>>(istream& is, vector& vs) { for (auto it = vs.begin(); it != vs.end(); it++) is >> *it; return is; } int N, K; vector A, B; void input() { cin >> N >> K; A.clear(); A.resize(N); for (int i = 0; i < N; i++) A[i] = i; for (int i = 0; i < K; i++) { int x, y; cin >> x >> y; x--; y--; swap(A[x], A[y]); } B.clear(); B.resize(N); for (int i = 0; i < N; i++) { cin >> B[i]; B[i]--; } vector C(N); for (int i = 0; i < N; i++) { C[ B[i] ] = i; } B = C; } void solve() { vector> ans; for (int i = 0; i < N; i++) { int dst = i; int src = -1; for (int j = i; j < N; j++) { if (A[j] == B[i]) { src = j; break; } } assert(src >= 0); if (dst == src) continue; int dir = (dst - src) / abs(dst - src); assert(dir == -1); for (int j = src; j != dst; j += dir) { ans.emplace_back(min(j, j + dir), max(j, j + dir)); swap(A[j], A[j + dir]); } } assert(A == B); cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) { cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl; } } } int main() { input(); solve(); return 0; }