#include <bits/stdc++.h>
using namespace std;
int Abs(int x) { return x < 0 ? -x : x; }
int vis[3005];
int dfn[3005];
int N[3005];
int X, Y;
int calc(int n, int tt) {
  for (int i = 1; i <= n; i++) vis[i] = 0;
  for (int i = 1; i <= n; i++) dfn[i] = 0;
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (vis[i] == 0) {
      cnt++;
      for (int j = i; vis[j] == 0; j = N[j]) vis[j] = cnt, dfn[cnt]++;
    }
  if (tt == 2) {
    for (int i = 1; i <= n; i++)
      if (vis[i] != vis[1]) {
        Y = i;
        break;
      }
    X = 1;
  }
  if (tt == 1) {
    for (int i = 1; i <= n; i++)
      if (dfn[vis[i]] > 1) {
        X = i;
        for (int j = i + 1; j <= n; j++)
          if (vis[i] == vis[j]) {
            Y = j;
            break;
          }
        break;
      }
  }
  return n - cnt;
}
int main() {
  int n, m;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> N[i];
  cin >> m;
  int now = calc(n, 0);
  cout << Abs(now - m) << endl;
  if (now < m)
    for (int i = now; i < m; i++) {
      calc(n, 2);
      swap(N[X], N[Y]);
      printf("%d %d%c", X, Y, i == m - 1 ? '\n' : ' ');
    }
  if (now > m)
    for (int i = m; i < now; i++) {
      calc(n, 1);
      swap(N[X], N[Y]);
      printf("%d %d%c", X, Y, i == now - 1 ? '\n' : ' ');
    }
  return 0;
}
