#include <bits/stdc++.h>
using namespace std;
int n, m;
int v[5005], a[5005];
int cal() {
  int sum = 0;
  memset(v, 0, sizeof(v));
  for (int i = 0; i < n; i++)
    if (v[i] == 0) {
      sum++;
      int k = i;
      while (v[k] == 0) {
        v[k] = sum;
        k = a[k];
      }
    }
  return sum;
}
int abs(int x) { return x < 0 ? -x : x; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i]--;
  }
  int ans = n - cal();
  scanf("%d", &m);
  printf("%d\n", abs(ans - m));
  while (ans != m) {
    if (ans > m) {
      for (int i = 0; i < n; i++)
        if (a[i] != i) {
          for (int j = i + 1; j < n; j++)
            if (v[i] == v[j]) {
              printf("%d %d\n", i + 1, j + 1);
              swap(a[i], a[j]);
              break;
            }
          break;
        }
    } else {
      for (int i = 1; i < n; i++)
        if (v[i] != v[0]) {
          printf("%d %d\n", 1, i + 1);
          swap(a[0], a[i]);
          break;
        }
    }
    ans = n - cal();
  }
  return 0;
}
