#include <bits/stdc++.h>
using namespace std;
int n, cyc[3010], a[3010], cn, m;
void calc_cyc() {
  memset(cyc, 0, sizeof(cyc));
  cn = 0;
  for (int i = 1; i <= n; i++)
    if (!cyc[i]) {
      int j = i;
      ++cn;
      while (!cyc[j]) {
        cyc[j] = cn;
        j = a[j];
      }
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &m);
  m = n - m;
  calc_cyc();
  if (cn == m) {
    puts("0");
  } else if (cn < m) {
    printf("%d\n", m - cn);
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n && cn < m; j++)
        if (cyc[j] == cyc[i]) {
          printf("%d %d ", i, j);
          swap(a[i], a[j]);
          calc_cyc();
        }
      if (cn == m) break;
    }
  } else {
    printf("%d\n", cn - m);
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n && m < cn; j++)
        if (cyc[i] != cyc[j]) {
          printf("%d %d ", i, j);
          swap(a[i], a[j]);
          calc_cyc();
        }
      if (cn == m) break;
    }
  }
  return 0;
}
