#include <bits/stdc++.h>
using namespace std;
void solutionD();
int main() {
  ios_base::sync_with_stdio(false);
  solutionD();
  return EXIT_SUCCESS;
}
long long n, m, p[4096], p2[4096], u[4096];
long long c[4096], sz[4096];
long long count() {
  for (long long i = 0; i < n; ++i) u[i] = 0;
  long long res2 = 0;
  for (long long i = 0; i < n; ++i) {
    if (u[i]) continue;
    long long len = 0;
    long long v = i;
    while (!u[v]) {
      ++len;
      u[v] = 1;
      v = p[v] - 1;
    }
    res2 += len - 1;
  }
  return res2;
}
void build() {
  for (long long i = 0; i < n; ++i) u[i] = 0;
  long long k = 0;
  for (long long i = 0; i < n; ++i) {
    if (u[i]) continue;
    long long v = i;
    while (!u[v]) {
      u[v] = 1;
      c[v] = k;
      v = p[v] - 1;
    }
    ++k;
  }
}
vector<pair<long long, long long>> solve_naive() {
  long long cnt = count();
  vector<pair<long long, long long>> ans;
  if (m > cnt) {
    for (long long i = 0; i < n && cnt < m; ++i) {
      build();
      long long index = -1;
      for (long long j = i + 1; j < n; ++j)
        if (c[i] != c[j]) {
          index = j;
          break;
        }
      if (index != -1) {
        swap(p[i], p[index]);
        ans.emplace_back(i, index);
        cnt = count();
        --i;
      }
    }
  } else if (m < cnt) {
    for (long long i = 0; i < n && cnt > m; ++i) {
      if (p[i] == i + 1) continue;
      build();
      long long index = -1;
      for (long long j = i + 1; j < n; ++j) {
        if (c[i] != c[j]) continue;
        index = j;
        break;
      }
      if (index != -1) {
        swap(p[i], p[index]);
        ans.emplace_back(i, index);
        cnt = count();
        --i;
      }
    }
  }
  return ans;
}
void solve() {
  vector<pair<long long, long long>> ans = solve_naive();
  cout << ans.size() << endl;
  for (auto it : ans) cout << it.first + 1 << " " << it.second + 1 << " ";
  cout << endl;
}
void solutionD() {
  for (; cin >> n;) {
    for (long long i = 0; i < n; ++i) cin >> p[i];
    cin >> m;
    solve();
    cerr << endl;
  }
}
