#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> P;
vector<int> vis;
vector<vector<int> > C;
vector<int> lab, sz;
void getCycle() {
  vis = vector<int>(N, 0);
  lab = vector<int>(N, 0);
  for (int i = 0; i < N; i++) {
    if (vis[i]) continue;
    C.push_back(vector<int>());
    sz.push_back(0);
    int u = i;
    while (!vis[u]) {
      vis[u] = 1;
      lab[u] = C.size() - 1;
      C.back().push_back(u);
      sz.back()++;
      u = P[u];
    }
  }
}
vector<int> tmp;
void mrg() {
  printf("1 ");
  for (int i = 1; i < N; i++) {
    if (lab[i] != lab[0]) {
      printf("%d ", i + 1);
      tmp.clear();
      tmp.push_back(0);
      for (int j = 1; j < C[lab[i]].size(); j++) {
        tmp.push_back(C[lab[i]][j]);
      }
      tmp.push_back(i);
      for (int j = 1; j < C[lab[0]].size(); j++) {
        tmp.push_back(C[lab[0]][j]);
      }
      C[lab[i]].clear();
      for (int j = 0; j < tmp.size(); j++) {
        lab[tmp[j]] = lab[0];
      }
      C[lab[0]] = tmp;
      return;
    }
  }
}
void split() {
  for (int i = 0; i < N; i++) {
    if (sz[lab[i]] > 1) {
      printf("%d ", i + 1);
      int idx = 1;
      for (int j = 1; j < C[lab[i]].size(); j++) {
        if (C[lab[i]][idx] > C[lab[i]][j]) {
          idx = j;
        }
      }
      printf("%d ", C[lab[i]][idx] + 1);
      tmp.clear();
      tmp.push_back(C[lab[i]][idx]);
      for (int j = 1; j < idx; j++) {
        tmp.push_back(C[lab[i]][j]);
      }
      C.push_back(tmp);
      sz.push_back(tmp.size());
      for (int j = 0; j < tmp.size(); j++) lab[tmp[j]] = C.size() - 1;
      tmp.clear();
      for (int j = 0; j < C[lab[i]].size(); j++) {
        if (lab[C[lab[i]][j]] == lab[i]) {
          tmp.push_back(C[lab[i]][j]);
        }
      }
      C[lab[i]] = tmp;
      sz[lab[i]] = tmp.size();
      return;
    }
  }
}
int main() {
  scanf("%d", &N);
  P.resize(N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &P[i]);
    P[i]--;
  }
  getCycle();
  scanf("%d", &M);
  M = N - M;
  if (C.size() < M) {
    printf("%d\n", M - C.size());
    for (int i = C.size(); i < M; i++) split();
  } else {
    printf("%d\n", C.size() - M);
    for (int i = C.size(); i > M; i--) mrg();
  }
}
