#include <bits/stdc++.h>
using namespace std;
int ar[3005];
int n, m, cnt;
bool used[3005];
void use(int v) {
  for (int i = v; !used[i]; i = ar[i]) {
    used[i] = 1;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    ar[i]--;
  }
  cin >> m;
  m = n - m;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      cnt++;
      use(i);
    }
  }
  memset(used, 0, sizeof used);
  cout << abs(cnt - m) << '\n';
  if (cnt > m) {
    use(0);
    for (int i = 1; i < n && cnt > m; i++) {
      if (!used[i]) {
        cout << 1 << ' ' << i + 1 << ' ';
        cnt--;
        use(i);
      }
    }
  }
  if (cnt < m) {
    for (int i = 0; i < n && cnt < m; i++) {
      vector<int> arrangement(n, -1);
      int cur = 0;
      for (int j = ar[i]; j != i; j = ar[j]) {
        arrangement[j] = cur++;
      }
      arrangement[i] = cur;
      cur = 0;
      for (int j = i + 1; j < n && cnt < m; j++) {
        if (arrangement[j] >= cur) {
          cout << i + 1 << ' ' << j + 1 << ' ';
          cnt++;
          cur = arrangement[j] + 1;
          swap(ar[i], ar[j]);
        }
      }
    }
  }
  return 0;
}
