#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int mod = 1000000007;
const double pi = acos(-1.0);
int a[3333];
int b[3333];
vector<int> v;
struct node {
  int l, r;
  node(int l1 = 0, int r1 = 0) {
    l = min(l1, r1);
    r = max(l1, r1);
  }
};
bool cmp(node a, node b) {
  if (a.l == b.l) return a.r < b.r;
  return a.l < b.l;
}
vector<node> ans;
int n;
void init() {
  for (int i = 0; i < 3333; i++) b[i] = 0;
  v.clear();
  for (int i = 1; i <= n; i++) {
    if (b[i] != 0) continue;
    v.push_back(i);
    int j = i;
    b[j] = i;
    j = a[j];
    while (!b[j]) {
      b[j] = i;
      j = a[j];
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int m;
  cin >> m;
  for (int i = 1; i <= n; i++) {
    if (b[i] != 0) continue;
    v.push_back(i);
    int j = i;
    b[j] = i;
    j = a[j];
    while (!b[j]) {
      b[j] = i;
      j = a[j];
    }
  }
  int l = n - v.size();
  if (m == l) {
    cout << 0 << endl << endl;
    return 0;
  }
  if (m > l) {
    cout << m - l << endl;
    for (int i = 1; i <= m - l; i++) cout << v[0] << " " << v[i] << " ";
    return 0;
  }
  cout << l - m << endl;
  int all = l - m;
  while (all--) {
    int pos;
    for (pos = 1; pos <= n; pos++)
      if (a[pos] != pos) break;
    for (int i = 1; i <= n; i++) {
      if (b[i] == b[pos] && i != pos) {
        ans.push_back(node(pos, i));
        int t = a[i];
        a[i] = a[pos];
        a[pos] = t;
        break;
      }
    }
    init();
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].l << " " << ans[i].r << " ";
  return 0;
}
