#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, p[3003], m;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", p + i);
  scanf("%d", &m);
  vector<int> ans;
  ans.clear();
  bool visit[3003];
  memset(visit, 0, sizeof(visit));
  for (int i = 1; i <= n; i++)
    if (!visit[i]) {
      ans.push_back(i);
      visit[i] = true;
      for (int indx = p[i]; indx != i; indx = p[indx]) visit[indx] = true;
    }
  int k = n - ans.size();
  if (k == m) {
    puts("0");
    return;
  }
  if (k < m) {
    printf("%d\n", m - k);
    for (int i = 1; k < m; k++, i++) {
      printf("%d %d ", ans[0], ans[i]);
    }
    return;
  }
  printf("%d\n", k - m);
  for (int i = 1; i <= n;) {
    if (p[i] == i) {
      i++;
      continue;
    }
    int mn = n + 1;
    for (int ind = p[i]; ind != i; ind = p[ind]) mn = min(mn, ind);
    printf("%d %d ", i, mn);
    swap(p[i], p[mn]);
    k--;
    if (m == k) return;
  }
}
int main() { solve(); }
