#include <bits/stdc++.h>
using namespace std;
int a[30005];
int f[30005];
int vis[30005];
int main() {
  int i, j, n, m;
  while (scanf("%d", &n) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    scanf("%d", &m);
    memset(vis, 0, sizeof(vis));
    int c = 0;
    for (i = 1; i <= n; i++) {
      if (vis[i]) continue;
      j = i;
      while (vis[j] == 0) {
        vis[j] = 1;
        f[j] = i;
        j = a[j];
      }
      c++;
    }
    int g = n - m - c;
    if (g < 0) g = -g;
    if (g == 0) {
      puts("0");
      continue;
    }
    if (g) {
      printf("%d\n", g);
      if (n - m > c) {
        int now = 1;
        for (int k = 0; k < g; k++) {
          while (1) {
            int flag = 0;
            for (i = now + 1; i <= n; i++) {
              if (f[i] == f[now]) {
                flag = 1;
                cout << now << " " << i << " ";
                swap(a[i], a[now]);
                for (j = 1; j <= n; j++) vis[j] = 0;
                for (j = 1; j <= n; j++) {
                  if (vis[j]) continue;
                  int w = j;
                  while (vis[w] == 0) {
                    vis[w] = 1;
                    f[w] = j;
                    w = a[w];
                  }
                }
                break;
              }
            }
            if (flag) break;
            now++;
          }
        }
        cout << endl;
      } else {
        int now = 1;
        for (int k = 0; k < g; k++) {
          int ok = 0;
          while (1) {
            ok++;
            if (ok >= 10) break;
            int flag = 0;
            for (i = now + 1; i <= n; i++) {
              if (f[i] != f[now]) {
                flag = 1;
                cout << now << " " << i << " ";
                swap(a[i], a[now]);
                for (j = 1; j <= n; j++) vis[j] = 0;
                for (j = 1; j <= n; j++) {
                  if (vis[j]) continue;
                  int w = j;
                  while (vis[w] == 0) {
                    vis[w] = 1;
                    f[w] = j;
                    w = a[w];
                  }
                }
                break;
              }
            }
            if (flag) break;
            now++;
          }
        }
        cout << endl;
      }
    }
  }
  return 0;
}
