#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int p[MAXN];
bool f[MAXN];
int cyc[MAXN];
int ccount = 0;
void create_cycles(int n) {
  memset(f, 0, n);
  ccount = 0;
  for (int i = 0; i < (int)(n); ++i)
    if (!f[i]) {
      f[i] = true;
      cyc[i] = ccount;
      int u = i;
      while (p[u] != i) {
        u = p[u];
        f[u] = true;
        cyc[u] = ccount;
      }
      ++ccount;
    }
}
int main(int argc, char **argv) {
  int n;
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) {
    cin >> p[i];
    --p[i];
  }
  create_cycles(n);
  int m;
  cin >> m;
  int cur = n - ccount;
  vector<pair<int, int> > ans;
  for (int i = 0; i < (int)(n); ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (cur < m && cyc[i] != cyc[j]) {
        swap(p[i], p[j]);
        ++cur;
        create_cycles(n);
        ans.push_back(make_pair(i, j));
      }
      if (cur > m && cyc[i] == cyc[j]) {
        swap(p[i], p[j]);
        --cur;
        create_cycles(n);
        ans.push_back(make_pair(i, j));
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < (int)(ans.size()); ++i) {
    cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << ' ';
  }
  return 0;
}
