#include <bits/stdc++.h>
using namespace std;
int p[3010], n, m;
vector<pair<int, int> > ans;
int preans;
void input() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", p + i);
  scanf("%d", &m);
  m = n - m;
}
void precalc() {
  static int vis[3010];
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      int j = i;
      do {
        vis[j] = 1;
        j = p[j];
      } while (j != i);
      ++preans;
    }
}
void split() {
  static int vis[3010];
  fill(vis + 1, vis + n + 1, 0);
  int tmp = 1;
  while (p[tmp] == tmp) ++tmp;
  int urv = tmp;
  do {
    vis[tmp] = 1;
    tmp = p[tmp];
  } while (tmp != urv);
  int todo = 1000000;
  for (int i = p[tmp]; i != tmp; i = p[i]) todo = min(todo, i);
  ans.push_back(make_pair(tmp, todo));
  swap(p[tmp], p[todo]);
}
void merge() {
  static int vis[3010];
  fill(vis + 1, vis + n + 1, 0);
  int tmp = 1;
  do {
    vis[tmp] = 1;
    tmp = p[tmp];
  } while (tmp != 1);
  int todo = 2;
  while (vis[todo]) ++todo;
  ans.push_back(make_pair(tmp, todo));
  swap(p[tmp], p[todo]);
}
void output() {
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); ++i)
    printf("%d %d%c", ans[i].first, ans[i].second,
           i + 1 == ans.size() ? '\n' : ' ');
}
int main() {
  input();
  precalc();
  if (m == preans)
    printf("0\n");
  else if (preans < m) {
    for (int i = 1; i <= m - preans; ++i) {
      split();
    }
    output();
  } else {
    for (int i = 1; i <= preans - m; ++i) merge();
    output();
  }
  return 0;
}
