#include <bits/stdc++.h>
using namespace std;
const int MN = 3011;
int n, need, a[MN], cycle[MN], cycleSize[MN], nCycle, current;
void init() {
  current = 0;
  nCycle = 0;
  memset(cycle, 0, sizeof cycle);
  for (int i = (1), _b = (n); i <= _b; i++)
    if (!cycle[i]) {
      ++nCycle;
      cycleSize[nCycle] = 0;
      int u = i;
      cycle[i] = nCycle;
      while (a[u] != i) {
        cycle[u] = nCycle;
        ++cycleSize[nCycle];
        u = a[u];
      }
      cycle[u] = nCycle;
      current += cycleSize[nCycle];
    }
}
int main() {
  ios ::sync_with_stdio(false);
  while (cin >> n) {
    for (int i = (1), _b = (n); i <= _b; i++) cin >> a[i];
    cin >> need;
    vector<int> res;
    res.clear();
    while (true) {
      init();
      if (current == need) break;
      if (current < need) {
        for (int i = (2), _b = (n); i <= _b; i++)
          if (cycle[i] != cycle[1]) {
            res.push_back(1);
            res.push_back(i);
            swap(a[1], a[i]);
            break;
          }
      } else {
        for (int i = (1), _b = (n); i <= _b; i++)
          if (cycleSize[cycle[i]] > 0) {
            for (int j = (1), _b = (n); j <= _b; j++)
              if (j != i && cycle[j] == cycle[i]) {
                res.push_back(i);
                res.push_back(j);
                swap(a[i], a[j]);
                break;
              }
            break;
          }
      }
    }
    cout << res.size() / 2 << endl;
    for (int i = 0, _a = (res.size()); i < _a; i++) cout << res[i] << ' ';
    cout << endl;
  }
  return 0;
}
