#include <bits/stdc++.h>
using namespace std;
int p[3010];
int marked[3010];
int fat[3010];
int getParent(int a) { return (fat[a] == a ? a : fat[a] = getParent(fat[a])); }
void mrg(int a, int b) {
  a = getParent(a);
  b = getParent(b);
  if (a == b) return;
  fat[b] = a;
}
void compute(int n) {
  for (int i = 1; i <= n; i++) fat[i] = i;
  for (int i = 1; i <= n; i++) mrg(i, p[i]);
}
int main() {
  int n, m;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    fat[i] = i;
  }
  cin >> m;
  memset(marked, -1, sizeof marked);
  int cnt = 0;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (marked[i] != -1) continue;
    while (marked[i] == -1) {
      marked[i] = cnt++;
      i = p[i];
    }
    ans += cnt - marked[i] - 1;
  }
  if (ans == m)
    cout << 0 << endl;
  else if (ans > m) {
    int i = 1;
    cout << ans - m << endl;
    while (ans > m) {
      compute(n);
      while (p[i] == i) i++;
      int j;
      for (j = i + 1; j <= n; j++)
        if (getParent(j) == getParent(i)) break;
      cout << i << " " << j << endl;
      swap(p[i], p[j]);
      ans--;
    }
    cout << endl;
  } else {
    int i = 2;
    cout << m - ans << endl;
    while (ans < m) {
      compute(n);
      while (getParent(i) == getParent(1)) i++;
      cout << 1 << " " << i << " ";
      swap(p[1], p[i]);
      ans++;
    }
    cout << endl;
  }
}
