#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3456;
int p[MAXN], par[MAXN], visit[MAXN];
void init(int n) {
  for (int i = 1; i <= n; i++) par[i] = i;
}
int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
bool merge(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return false;
  par[x] = y;
  return true;
}
int main() {
  int n, m;
  scanf("%d", &n);
  init(n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  scanf("%d", &m);
  int sum = n;
  for (int i = 1; i <= n; i++) {
    if (p[i] == i) continue;
    if (merge(p[i], p[p[i]])) sum--;
  }
  int ans = n - sum;
  if (ans >= m) {
    printf("%d\n", ans - m);
    int cur = 1, cnt = 0;
    while (cnt != ans - m) {
      int MIN = n + 1;
      if (p[cur] == cur) {
        cur++;
        continue;
      }
      memset(visit, 0, sizeof(visit));
      visit[cur] = true;
      int tmp = p[cur];
      while (!visit[tmp]) {
        MIN = min(tmp, MIN);
        visit[tmp] = true;
        tmp = p[tmp];
      }
      printf("%d %d ", cur, MIN);
      cnt++;
      swap(p[cur], p[MIN]);
    }
    puts("");
  } else {
    int need = m - ans;
    printf("%d\n", need);
    int tp = 2;
    for (int i = 0; i < need; i++) {
      while (!merge(p[tp], p[1]) && tp <= n) tp++;
      printf("%d %d ", 1, tp);
    }
    puts("");
  }
  return 0;
}
