#include <bits/stdc++.h>
using namespace std;
const int MAX = 3030;
int p[MAX];
vector<int> cicles[MAX];
int nC;
bitset<MAX> visited;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < int(n); i++) scanf("%d", p + i + 1);
  int m;
  scanf("%d", &m);
  int S = 0;
  nC = 0;
  for (int i = 1; i <= n; i++)
    if (!visited[i]) {
      int u = i;
      while (true) {
        visited[u] = true;
        cicles[nC].push_back(u);
        u = p[u];
        if (u == i) break;
      }
      nC++;
    }
  S = n - nC;
  int ans = abs(m - S);
  printf("%d\n", ans);
  if (S > m) {
    while (S != m) {
      visited.reset();
      nC = 0;
      for (int i = 1; i <= n; i++)
        if (!visited[i]) {
          cicles[nC].clear();
          int u = i;
          while (true) {
            visited[u] = true;
            cicles[nC].push_back(u);
            u = p[u];
            if (u == i) break;
          }
          nC++;
        }
      for (int i = 0; i < nC; i++)
        if (((int)(cicles[i]).size()) > 1) {
          int mn = 1e8;
          for (int j = 1; j < ((int)(cicles[i]).size()); j++)
            mn = min(mn, cicles[i][j]);
          printf("%d %d ", cicles[i][0], mn);
          swap(p[cicles[i][0]], p[mn]);
          S--;
          break;
        }
    }
    printf("\n");
  } else if (S < m) {
    while (S != m) {
      visited.reset();
      nC = 0;
      for (int i = 1; i <= n; i++)
        if (!visited[i]) {
          cicles[nC].clear();
          int u = i;
          while (true) {
            visited[u] = true;
            cicles[nC].push_back(u);
            u = p[u];
            if (u == i) break;
          }
          nC++;
        }
      S++;
      printf("%d %d ", cicles[0][0], cicles[1][0]);
      swap(p[cicles[0][0]], p[cicles[1][0]]);
    }
    printf("\n");
  }
}
