#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3000;
const int INF = 1 << 30;
int ps[MAX_N];
bool used[MAX_N];
set<pair<int, int> > rs;
pair<int, int> sws[MAX_N];
inline int loop(int st, int &mini) {
  int l = 0;
  mini = INF;
  for (int i = ps[st]; i != st; i = ps[i], l++)
    if (mini > i) mini = i;
  if (mini >= INF) mini = st;
  return l;
}
void printloop(int st) {
  printf("%d", st + 1);
  for (int i = ps[st]; i != st; i = ps[i]) printf(" %d", i + 1);
  putchar('\n');
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", ps + i), ps[i]--;
  int m;
  scanf("%d", &m);
  int fp = n;
  for (int i = 0; i < n; i++)
    if (!used[i]) {
      used[i] = true;
      int l = 0;
      for (int j = ps[i]; !used[j]; j = ps[j]) used[j] = true, l++;
      rs.insert(pair<int, int>(i, l));
      fp--;
    }
  int k = 0;
  while (fp != m) {
    if (fp > m) {
      while (!rs.empty() && rs.begin()->second == 0) rs.erase(rs.begin());
      int u = rs.begin()->first, v;
      loop(u, v);
      rs.erase(rs.begin());
      sws[k++] = pair<int, int>(u, v);
      swap(ps[u], ps[v]);
      int tu, tv;
      int ul = loop(u, tu), vl = loop(v, tv);
      if (ul > 0) rs.insert(pair<int, int>(u, ul));
      if (vl > 0) rs.insert(pair<int, int>(v, vl));
      fp--;
    } else {
      set<pair<int, int> >::iterator sit = rs.begin();
      int u = sit->first, ul = sit->second;
      rs.erase(sit);
      sit = rs.begin();
      int v = sit->first, vl = sit->second;
      rs.erase(sit);
      sws[k++] = pair<int, int>(u, v);
      swap(ps[u], ps[v]);
      rs.insert(pair<int, int>(u, ul + vl + 1));
      fp++;
    }
  }
  printf("%d\n", k);
  for (int i = 0; i < k; i++) {
    if (i) putchar(' ');
    printf("%d %d", sws[i].first + 1, sws[i].second + 1);
  }
  putchar('\n');
  return 0;
}
