#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
int p[3000 + 1];
int cyc[3000 + 1];
int n_cycles;
vector<pair<int, int>> ans;
void build() {
  n_cycles = 0;
  memset(cyc, 0, sizeof cyc);
  for (int i = 1; i <= n; i++) {
    if (not cyc[i]) {
      n_cycles++;
      int j = i;
      while (not cyc[j]) {
        cyc[j] = n_cycles;
        j = p[j];
      }
    }
  }
}
void increase() {
  int besti = 1;
  while (p[besti] == besti) {
    besti++;
  }
  int bestj = 1;
  while (cyc[bestj] != cyc[besti] or bestj == besti) {
    bestj++;
  }
  ans.push_back({besti, bestj});
  swap(p[besti], p[bestj]);
}
void decrease() {
  int besti = 1;
  int bestj = 1;
  while (cyc[bestj] == cyc[besti] or bestj == besti) {
    bestj++;
  }
  ans.push_back({besti, bestj});
  swap(p[besti], p[bestj]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  cin >> m;
  build();
  while (n_cycles < n - m) {
    increase();
    build();
  }
  while (n_cycles > n - m) {
    decrease();
    build();
  }
  cout << ans.size() << '\n';
  for (auto p : ans) {
    cout << p.first << " " << p.second << " ";
  }
  cout << '\n';
  return 0;
}
