#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
const int N = 200005;
vector<int> s[N], tmp;
int cnt, n, m, a[N];
bool vis[N];
void cal() {
  cnt = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++)
    if (vis[i] == 0) {
      int t = i;
      s[cnt].clear();
      while (vis[t] == 0) {
        vis[t] = 1;
        s[cnt].push_back(t);
        t = a[t];
      }
      cnt++;
    }
  for (int i = 0; i <= cnt - 1; i++) sort(s[i].begin(), s[i].end());
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  cal();
  int op = n - cnt;
  scanf("%d", &m);
  if (op < m) {
    tmp.clear();
    for (int i = 0; i <= cnt - 1; i++) tmp.push_back(s[i][0]);
    sort(tmp.begin(), tmp.end());
    int nn = m - op;
    printf("%d\n", nn);
    for (int i = 1; i <= nn; i++) printf("%d %d ", tmp[0], tmp[i]);
  } else if (op > m) {
    int nn = op - m;
    printf("%d\n", nn);
    for (int ca = 1; ca <= nn; ca++) {
      pair<int, int> x(n + 1, n + 1);
      cal();
      for (int i = 0; i <= cnt - 1; i++)
        if (s[i].size() > 1) {
          pair<int, int> t(s[i][0], s[i][1]);
          x = min(x, t);
        }
      swap(a[x.first], a[x.second]);
      printf("%d %d ", x.first, x.second);
    }
  } else
    printf("0\n");
  return 0;
}
