#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[3010], d[3010];
void danhdau(int xp) {
  int i;
  while (d[xp] == 0) {
    d[xp] = 1;
    xp = a[xp];
  }
}
void solve() {
  int i, j, vongco, vongcan;
  int temp, idx;
  memset(d, 0, sizeof(d));
  vongco = 0;
  for (i = 1; i <= n; i++)
    if (d[i] == 0) {
      vongco++;
      danhdau(i);
    }
  vongcan = n - m;
  printf("%d\n", abs(vongco - vongcan));
  if (vongco > vongcan) {
    memset(d, 0, sizeof(d));
    danhdau(1);
    for (i = 2; i <= n && vongcan < vongco; i++)
      if (d[i] == 0) {
        vongcan++;
        danhdau(i);
        printf("%d %d ", 1, i);
      }
  }
  if (vongco < vongcan) {
    for (i = 1; i <= n && vongco < vongcan; i++) {
      memset(d, 0, sizeof(d));
      idx = 1;
      temp = a[i];
      while (temp != i) {
        d[temp] = idx++;
        temp = a[temp];
      }
      d[i] = idx;
      idx = 1;
      for (j = i + 1; j <= n && vongco < vongcan; j++)
        if (d[j] >= idx) {
          vongco++;
          swap(a[i], a[j]);
          idx = d[j] + 1;
          printf("%d %d ", i, j);
        }
    }
  }
}
void input() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  solve();
}
int main() {
  input();
  fclose(stdin);
  fclose(stdout);
  return 0;
}
