#include #include void solve() { int n, k; std::cin >> n >> k; std::vector> ps(k); for (auto& p : ps) { std::cin >> p.first >> p.second; --p.first, --p.second; } std::vector xs(n); for (auto& x : xs) { std::cin >> x; --x; } for (auto p : ps) { std::swap(xs[p.first], xs[p.second]); } std::vector> ans; bool update = true; while (update) { update = false; for (int i = 0; i + 1 < n; ++i) { if (xs[i] > xs[i + 1]) { ans.emplace_back(i, i + 1); std::swap(xs[i], xs[i + 1]); update = true; } } } std::cout << ans.size() << "\n"; for (auto p : ans) { std::cout << p.first + 1 << " " << p.second + 1 << "\n"; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }