#include <bits/stdc++.h>
using namespace std;
int arr[5120], num[5120], sz[5120];
bool vis[5120];
int main() {
  int n, m;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
    arr[i]--;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (vis[i]) continue;
    int x = i;
    while (true) {
      if (vis[x]) break;
      vis[x] = true;
      num[x] = cnt;
      sz[cnt]++;
      x = arr[x];
    }
    cnt++;
  }
  scanf("%d", &m);
  int orig = cnt;
  cnt = n - cnt;
  if (cnt == m) {
    printf("0\n");
    return 0;
  }
  if (cnt > m) {
    printf("%d\n", cnt - m);
    for (int i = 0; i < n && cnt > m; i++) {
      if (arr[i] == i) continue;
      for (int j = i + 1; j < n && cnt > m; j++) {
        if (arr[j] == j || num[i] != num[j]) continue;
        printf("%d %d ", i + 1, j + 1);
        swap(arr[i], arr[j]);
        cnt--;
        if (arr[i] == i) {
          num[i] = -1;
          break;
        } else
          num[i] = num[arr[i]];
        if (arr[j] == j)
          num[j] = -1;
        else {
          num[j] = orig;
          for (int x = arr[j]; num[x] != orig; x = arr[x]) num[x] = orig;
          orig++;
        }
      }
    }
    return 0;
  }
  printf("%d\n", m - cnt);
  for (int i = 1; i < n && cnt < m; i++) {
    if (num[i] != num[0]) {
      cnt++;
      for (int j = i; num[j] != num[0]; j = arr[j]) num[j] = num[0];
      printf("%d %d ", 1, i + 1);
    }
  }
  return 0;
}
