#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3 * 1010, INF = 0x3f3f3f3f;
int n, m, c = 0, p[MAXN], cycle[MAXN], minCycle[MAXN];
void calcCycles() {
  memset(cycle, false, sizeof cycle);
  memset(minCycle, INF, sizeof minCycle);
  c = 0;
  for (int i = 1, x; i <= n; ++i)
    if (!cycle[i]) {
      x = i, c++;
      while (!cycle[x])
        minCycle[i] = min(minCycle[i], x), cycle[x] = i, x = p[x];
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
  scanf("%d", &m);
  calcCycles();
  printf("%d\n", abs(n - m - c));
  int cur = 2, x;
  while (n - m < c) {
    while (cycle[cur] == 1) cur++;
    printf("%d %d ", 1, cur);
    swap(p[1], p[cur]);
    calcCycles();
  }
  cur = 1;
  while (n - m > c) {
    pair<int, int> minP{INF, INF};
    for (int i = 1; i <= n; ++i)
      if (minCycle[cycle[i]] != i)
        minP = min(minP, make_pair(minCycle[cycle[i]], i));
    printf("%d %d ", minP.first, minP.second);
    swap(p[minP.first], p[minP.second]);
    calcCycles();
  }
}
