#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3000 + 10;
int n, m, k, p[MAXN], b[MAXN];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> p[i];
  for (int i = 1; i <= n; ++i)
    if (!b[i]) {
      b[i] = i;
      ++k;
      for (int j = p[i]; j != i; b[j] = i, j = p[j])
        ;
    }
  cin >> m;
  k = n - k;
  if (k == m) puts("0"), exit(0);
  if (m < k) {
    cout << k - m << endl;
    for (int t = 1; t <= k - m; ++t) {
      int i = 1, j = 1;
      for (; p[i] == i; ++i)
        ;
      j = p[i];
      for (int first = i; p[first] != i; first = p[first]) j = min(j, p[first]);
      cout << i << " " << j << " ";
      swap(p[i], p[j]);
    }
    cout << endl;
  } else {
    cout << m - k << endl;
    for (int t = 1; t <= m - k; ++t) {
      memset(b, 0, sizeof(b));
      b[1] = 1;
      for (int i = p[1]; i != 1; b[i] = 1, i = p[i])
        ;
      int j = 1;
      for (; b[j] == 1; ++j)
        ;
      cout << 1 << " " << j << " ";
      swap(p[1], p[j]);
    }
    cout << endl;
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
