#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 6;
const int mod = 1e9 + 7;
int b[N], n, m, ans;
int vis[N], sz[N], tot;
void rebuild() {
  memset(vis, 0, sizeof vis);
  tot = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i])
      vis[i] = i;
    else
      continue;
    ++tot;
    int u = b[i];
    sz[i] = 1;
    while (u != i) {
      sz[i]++;
      vis[u] = i;
      u = b[u];
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", b + i);
  scanf("%d", &m);
  rebuild();
  printf("%d\n", abs(m - n + tot));
  if (n - tot > m) {
    while (n - tot > m) {
      for (int i = 1; i <= n; i++) {
        if (sz[vis[i]] <= 1) continue;
        for (int j = i + 1; j <= n; j++) {
          if (vis[j] == vis[i]) {
            swap(b[i], b[j]);
            printf("%d %d ", i, j);
            break;
          }
        }
        break;
      }
      rebuild();
    }
  } else {
    while (n - tot < m) {
      for (int j = 2; j <= n; j++) {
        if (vis[j] != vis[1]) {
          swap(b[1], b[j]);
          printf("%d %d ", 1, j);
          break;
        }
      }
      rebuild();
    }
  }
  return 0;
}
