#include <bits/stdc++.h>
using namespace std;
int a[3005];
int bl[3005];
int sz[3005];
int n, k;
void dfs2(int x, int b) {
  bl[x] = b;
  sz[b]++;
  if (!bl[a[x]]) {
    dfs2(a[x], b);
  }
}
int dfs() {
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!bl[i]) {
      cnt++;
      dfs2(i, i);
    }
  }
  return cnt;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &k);
  int sum = dfs();
  int les = n - sum;
  printf("%d\n", abs(k - les));
  if (k > les) {
    for (int i = 1; i <= k - les; i++) {
      for (int j = 1; j <= n; j++) {
        if (bl[j] != bl[1]) {
          printf("%d %d ", 1, j);
          swap(a[1], a[j]);
          memset(bl, 0, sizeof(bl));
          memset(sz, 0, sizeof(sz));
          dfs();
          break;
        }
      }
    }
  } else {
    for (int i = 1; i <= les - k; i++) {
      int flag = 0;
      for (int j = 1; j <= n; j++) {
        if (sz[j] != 1) {
          for (int k = 1; k <= n; k++) {
            if (j != k && bl[j] == bl[k]) {
              flag = 1;
              printf("%d %d ", j, k);
              swap(a[j], a[k]);
              memset(bl, 0, sizeof(bl));
              memset(sz, 0, sizeof(sz));
              dfs();
              break;
            }
          }
        }
        if (flag) break;
      }
    }
  }
  puts("");
}
