#include <bits/stdc++.h>
using namespace std;
int parents[100010];
int find(int x) {
  if (x == parents[x])
    return x;
  else
    return parents[x] = find(parents[x]);
}
void uni(int x, int y) {
  x = find(x);
  y = find(y);
  parents[y] = x;
}
int cnt[100010];
int ans[100010], k = 0;
int x[100010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) parents[i] = i;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
    uni(i, x[i]);
  }
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) cnt[find(i)]++;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (!cnt[i]) continue;
    sum += cnt[i] - 1;
  }
  int flag = 0;
  if (sum == m) {
    printf("0\n");
    return 0;
  } else if (sum < m) {
    for (int i = 1; i <= n; i++) {
      if (sum == m) break;
      for (int j = i + 1; j <= n; j++) {
        if (sum == m) break;
        if (find(i) != find(j)) {
          sum++;
          ans[k++] = i;
          ans[k++] = j;
          uni(i, j);
        }
      }
    }
  } else if (sum > m) {
    for (int i = 1; i <= n; i++) {
      if (sum == m) break;
      for (int j = i + 1; j <= n; j++) {
        if (sum == m) break;
        if (find(i) == find(j)) {
          ans[k++] = i;
          ans[k++] = j;
          swap(x[i], x[j]);
          for (int l = 1; l <= n; l++) parents[l] = l;
          for (int l = 1; l <= n; l++) uni(l, x[l]);
          sum--;
        }
      }
    }
  }
  printf("%d\n", k >> 1);
  for (int i = 0; i < k; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
