#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) #define minimize(a, x) a = std::min(a, x) #define maximize(a, x) a = std::max(a, x) typedef long long ll; int const inf = 1<<29; int main() { int N, K; cin >> N >> K; int arr[N]; iota(arr, arr + N, 0); rep(i, K) { int x, y; cin >> x >> y; swap(arr[x-1], arr[y-1]); } int A[N]; rep(i, N) { cin >> A[i]; A[i] --; } vector> s; rep(i, N) rep(j, N-1) { if(A[arr[j]] > A[arr[j+1]]) { s.emplace_back(j, j+1); swap(arr[j], arr[j+1]); } } cout << s.size() << endl; rep(i, s.size()) { cout << ++s[i].first << " " << ++s[i].second << endl; } return 0; }