#include <bits/stdc++.h>
using namespace std;
using lli = long long;
using ld = long double;
mt19937 rnd(time(nullptr));
int n = 0, m = 0;
vector<int> data;
vector<bool> used;
vector<vector<int>> color;
void DFS(int v) {
  used[v] = true;
  color.back().push_back(v);
  if (!used[data[v]]) DFS(data[v]);
}
inline void Solve() {
  cin >> n;
  data.resize(n);
  used.resize(n);
  for (auto &it : data) {
    cin >> it;
    it--;
  }
  cin >> m;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      color.push_back(vector<int>());
      DFS(i);
    }
  }
  int c = color.size();
  if (c > (n - m)) {
    cout << (c - (n - m)) << '\n';
    for (int i = 1, j = 0; j < (c - (n - m)); i++, j++) {
      cout << 1 << ' ' << color[i][0] + 1 << ' ';
    }
  } else {
    cout << ((n - m) - c) << '\n';
    for (int i = 0, j = 0; j < ((n - m) - c); i++) {
      vector<int> pos(n, -1);
      int current = 1;
      for (int x = data[i]; x != i; x = data[x]) {
        pos[x] = current++;
      }
      pos[i] = current;
      current = 0;
      for (int x = i + 1; (x < n) && (j < ((n - m) - c)); x++) {
        if (pos[x] > current) {
          current = pos[x];
          cout << i + 1 << ' ' << x + 1 << ' ';
          swap(data[i], data[x]);
          j++;
        }
      }
    }
  }
}
signed main() {
  cout << fixed << setprecision(20);
  Solve();
  return 0;
}
