#include <bits/stdc++.h>
using namespace std;
vector<int> leaders;
int n, m, cnt = 0, perm[1048576], visited[1048576];
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n + 1; i++) scanf("%d", &perm[i]);
  scanf("%d", &m);
  for (int i = 1; i < n + 1; i++) {
    if (!visited[i]) {
      leaders.push_back(i);
      int k = i;
      while (!visited[k]) {
        visited[k] = 1;
        k = perm[k];
      }
      cnt++;
    }
  }
  reverse(leaders.begin(), leaders.end());
  leaders.pop_back();
  if (n - cnt >= m) {
    printf("%d\n", n - cnt - m);
    int i = 1;
    while (n - cnt - m) {
      if (perm[i] != i) {
        int k = perm[i], mi = 2147483647;
        while (k != i) {
          if (k < mi) mi = k;
          k = perm[k];
        }
        printf("%d %d ", i, mi);
        swap(perm[i], perm[mi]);
        cnt++;
      } else
        i++;
    }
  } else {
    printf("%d\n", m - n + cnt);
    while (m - n + cnt) {
      printf("1 %d ", leaders.back());
      leaders.pop_back();
      cnt--;
    }
  }
  return 0;
}
