#include <bits/stdc++.h>
using namespace std;
void scanint(int &x) {
  register int c = getchar();
  x = 0;
  for (; (c < 48 || c > 57); c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
}
int p[4000];
bool seen[4000];
void cyclate(int st) {
  int i;
  for (i = st; !seen[i]; i = p[i]) {
    seen[i] = true;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, i, j, k, cyc, cur;
  memset(seen, false, sizeof(seen));
  ;
  scanint(n);
  for (i = 1; i <= n; i++) scanint(p[i]);
  scanint(m);
  cyc = 0;
  m = n - m;
  for (i = 1; i <= n; i++) {
    if (!seen[i]) {
      cyc++;
      cyclate(i);
    }
  }
  printf("%d\n", abs(m - cyc));
  memset(seen, false, sizeof(seen));
  ;
  if (m < cyc) {
    cyclate(1);
    for (i = 1; i <= n && cyc > m; i++) {
      if (!seen[i]) {
        cyclate(i);
        printf("%d %d ", 1, i);
        cyc--;
      }
    }
  }
  if (m > cyc) {
    for (i = 1; i <= n && cyc < m; i++) {
      vector<int> pos(n + 1, -1);
      cur = 0;
      for (j = p[i]; j != i; j = p[j]) pos[j] = cur++;
      pos[i] = cur;
      cur = 0;
      for (j = i + 1; j <= n && cyc < m; j++) {
        if (pos[j] >= cur) {
          cur = pos[j] + 1;
          cyc++;
          printf("%d %d ", i, j);
          swap(p[i], p[j]);
        }
      }
    }
  }
  return 0;
}
