#include <bits/stdc++.h>
using namespace std;
int countCircles(const vector<int>& a) {
  vector<char> b(a.size());
  int count = 0;
  int n = a.size();
  for (int i = 0; i < n; ++i) {
    if (b[i]) continue;
    ++count;
    for (int j = i; !b[j]; j = a[j] - 1) {
      b[j] = 1;
    }
  }
  return count;
}
void splitCircles(vector<int>& a, int k) {
  int n = a.size();
  for (int i = 0; i < n && k; ++i) {
    while (k) {
      int b = n;
      for (int j = a[i] - 1; j != i; j = a[j] - 1) {
        b = min(b, j);
      }
      if (b == n) break;
      cout << i + 1 << ' ' << b + 1 << ' ';
      swap(a[i], a[b]);
      --k;
    }
  }
  cout << endl;
}
void joinCircles(vector<int>& a, int k) {
  vector<char> b(a.size());
  int n = a.size();
  for (int i = 0; i < n && k; ++i) {
    if (b[i]) continue;
    if (i) {
      --k;
      cout << 1 << ' ' << i + 1 << ' ';
    }
    for (int j = i; !b[j]; j = a[j] - 1) {
      b[j] = 1;
    }
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  vector<int> ar(n);
  for (int i = 0; i < n; ++i) cin >> ar[i];
  int m;
  cin >> m;
  int c = countCircles(ar);
  cout << abs((n - c) - m) << endl;
  if (n - m > c) {
    splitCircles(ar, (n - m) - c);
  } else if (n - m < c) {
    joinCircles(ar, c - (n - m));
  }
}
