#include <bits/stdc++.h>
using namespace std;
int p[3001], h[3001];
int main() {
  int n, m, i, j, k, hcnt, t, x;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> p[i];
  cin >> m;
  for (hcnt = 0, i = 1; i <= n; i++) {
    if (h[i] == 0) {
      h[i] = i;
      for (j = p[i]; j != i; j = p[j]) h[j] = i;
      hcnt++;
    }
  }
  if (n - hcnt == m)
    cout << 0 << endl;
  else if (n - hcnt > m) {
    i = n - hcnt - m;
    cout << i << endl;
    while (i--) {
      for (j = 1; p[j] == j; j++)
        ;
      for (k = j, x = p[j]; p[k] != j; k = p[k])
        if (p[k] < x) x = p[k];
      cout << j << " " << x << " ";
      t = p[j];
      p[j] = p[x];
      p[x] = t;
    }
    cout << endl;
  } else {
    i = m + hcnt - n;
    cout << i << endl;
    while (i--) {
      for (j = 1; j <= n; j++) h[j] = 0;
      for (h[1] = 1, j = p[1]; j != 1; j = p[j]) h[j] = 1;
      for (j = 1; h[j] == 1; j++)
        ;
      cout << "1 " << j << " ";
      t = p[j];
      p[j] = p[1];
      p[1] = t;
    }
    cout << endl;
  }
  return 0;
}
