#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 7;
int a[maxn];
int vis[maxn];
vector<int> huan[maxn];
int link[maxn];
vector<int> ans;
int belong[maxn];
void dfs(int now, int index) {
  if (vis[now]) return;
  vis[now] = 1;
  belong[now] = index;
  huan[index].push_back(now);
  dfs(a[now], index);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int m;
  scanf("%d", &m);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i, cnt);
      cnt++;
    }
  }
  int fp = 0;
  for (int i = 0; i < cnt; i++) {
    fp += huan[i].size() - 1;
  }
  if (fp == m) {
    printf("0\n\n");
  } else if (fp > m) {
    int times = fp - m;
    int index = 0;
    printf("%d\n", times);
    while (times--) {
      int i;
      for (i = 1; i <= n; i++) {
        if (a[i] != i) {
          break;
        }
      }
      int j;
      int y = a[i];
      for (j = a[i]; j != i; j = a[j]) {
        y = min(y, j);
      }
      swap(a[i], a[y]);
      printf("%d %d ", i, y);
    }
  } else {
    int times = m - fp;
    printf("%d\n", times);
    for (int i = 0; i < cnt; i++) link[i] = 3005;
    for (int i = 1; i <= n; i++) {
      link[belong[i]] = min(link[belong[i]], i);
    }
    for (int i = 0; i < cnt; i++) {
      ans.push_back(link[i]);
    }
    sort(ans.begin(), ans.end());
    for (int i = 1; i <= times; i++) {
      printf("1 %d ", ans[i]);
    }
  }
}
