#include #include #include #include #include #include using namespace std; void show(vector &v) { for (auto e : v) { cout << e << " "; } cout << endl; } int main() { int n, k; cin >> n >> k; vector x(k), y(k), a(n); for (int i = 0; i < k; i++) { cin >> x[i]; cin >> y[i]; x[i]--; y[i]--; } for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } for (int i = 0; i < k; i++) { swap(a[x[i]], a[y[i]]); } // show(a); list xx; for (int i = 0; i < n; i++) { int pos = find(a.begin(), a.end(), i) - a.begin(); while (pos > i) { swap(a[pos], a[pos-1]); xx.emplace_back(pos-1 + 1); pos--; } } // show(a); cout << xx.size() << endl; for (auto e : xx) { cout << e << " " << e + 1 << endl; } return 0; }