#include <bits/stdc++.h>
using namespace std;
int n, m, now;
int a[3005], b[3005];
int vis[3005], f[3005], c[3005];
int ok[3005];
int findcir(int *a, int n) {
  int ret = 0;
  for (int i = 1; i <= n; i++) b[a[i]] = i;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    int j;
    ret++;
    for (j = i; !vis[j]; j = b[j]) {
      f[j] = ret;
      vis[j] = 1;
      c[ret]++;
    }
  }
  return ret;
}
void Swap(int x) {
  if (!x) return;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      if (f[i] == f[j]) {
        printf("%d %d ", i, j);
        x--;
        if (!x) return;
        swap(a[i], a[j]);
        findcir(a, n);
      }
}
void move(int x) {
  if (!x) return;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      if (f[i] != f[j]) {
        printf("%d %d ", i, j);
        x--;
        if (!x) return;
        swap(a[i], a[j]);
        findcir(a, n);
      }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  now = findcir(a, n);
  now = n - now;
  scanf("%d", &m);
  printf("%d\n", abs(now - m));
  if (now > m) {
    Swap(now - m);
  } else
    move(m - now);
  return 0;
}
