#include <bits/stdc++.h>
using namespace std;
int a[3005];
bool b[3005];
int main() {
  int n, m, i, j, s = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) {
    if (!b[i]) {
      b[i] = true;
      for (j = a[i]; j != i; j = a[j]) {
        b[j] = true;
        s++;
      }
    }
  }
  scanf("%d", &m);
  printf("%d\n", abs(s - m));
  int ansx, ansy;
  while (s != m) {
    if (s <= m) {
      s++;
      ansx = 1;
      memset(b, 0, sizeof(b));
      b[1] = true;
      for (i = a[ansx]; i != 1; i = a[i]) b[i] = 1;
      i = 1;
      for (i = 1; b[i]; i++)
        ;
      ansy = i;
    } else {
      s--;
      for (i = 1; i <= n; i++) {
        if (a[i] != i) {
          ansx = i;
          break;
        }
      }
      ansy = a[i];
      for (j = a[i]; j != i; j = a[j]) ansy = min(j, ansy);
    }
    swap(a[ansx], a[ansy]);
    printf("%d %d ", ansx, ansy);
  }
  puts("");
  return 0;
}
