#include <bits/stdc++.h>
using namespace std;
int p[3030], seen[3030];
int n, k, m;
int calc_seen() {
  int d = 0;
  memset(seen, 0, sizeof seen);
  for (int i = (0); i < (n); ++i) {
    if (!seen[i]) {
      d++;
      for (int j = p[i]; !seen[j]; j = p[j]) seen[j] = d;
      seen[i] = d;
    }
  }
  return d;
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &p[i]);
    p[i]--;
  }
  scanf("%d", &m);
  m = n - m;
  k = calc_seen();
  printf("%d\n", abs(k - m));
  if (k < m) {
    for (int i = 0; i < n && k < m; ++i)
      for (int j = i + 1; j < n && k < m; ++j) {
        if (seen[i] == seen[j]) {
          printf("%d %d\n", i + 1, j + 1);
          swap(p[i], p[j]);
          calc_seen();
          k++;
        }
      }
  } else if (k > m) {
    for (int i = 1; i < n && (k > m); ++i)
      if (seen[i] != seen[0]) {
        printf("1  %d\n", i + 1);
        swap(p[0], p[i]);
        calc_seen();
        k--;
      }
  }
  return 0;
}
