#include <bits/stdc++.h>
using namespace std;
stack<time_t> time_stack;
void startTimer() { time_stack.push(clock()); }
double stopTimer() {
  double time = clock() - time_stack.top();
  time_stack.pop();
  return time / double(CLOCKS_PER_SEC);
}
double sqr(double x) { return x * x; }
vector<int> p;
vector<int> used;
void cover(int i) {
  for (int j = i; !used[j]; j = p[j]) used[j] = true;
}
int main() {
  startTimer();
  ios::sync_with_stdio(false);
  string TASK = "immediate";
  cout.precision(9);
  cout << fixed;
  int n;
  cin >> n;
  p.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  used.assign(n, false);
  int c = 0;
  for (int i = 0; i < n; i++)
    if (!used[i]) {
      c++;
      cover(i);
    }
  used.assign(n, false);
  int m;
  cin >> m;
  vector<pair<int, int> > ans;
  if (c > n - m) {
    cover(0);
    for (int i = 1; i < n && c > n - m; i++)
      if (!used[i]) {
        c--;
        cover(i);
        ans.push_back(make_pair(0, i));
      }
  } else if (c < n - m) {
    for (int i = 0; i < n && c < n - m; i++) {
      used.assign(n, -1);
      int c_sz = 0;
      for (int j = p[i]; j != i; j = p[j]) used[j] = c_sz++;
      used[i] = c_sz;
      int mx = -1;
      for (int j = i + 1; j < n && c < n - m; j++)
        if (used[j] > mx) {
          c++;
          ans.push_back(make_pair(i, j));
          swap(p[i], p[j]);
          mx = used[j];
        }
    }
  }
  cout << ans.size() << endl;
  for (auto it : ans) cout << it.first + 1 << " " << it.second + 1 << " ";
  cout << endl;
  return 0;
}
