#include <bits/stdc++.h>
using namespace std;
int cyclenum[3005];
int cyclelength[3005];
int p[3005];
int n;
int cyclestruct() {
  queue<int> nums;
  int ct = 0;
  for (int i = 1; i <= n; ++i) cyclenum[i] = -1;
  for (int i = 1; i <= n; ++i) {
    int k = i;
    if (cyclenum[i] != -1) continue;
    nums.push(i);
    for (int o = 0; o >= 0; ++o) {
      i = p[i];
      if (i == k) break;
      nums.push(i);
    }
    int u = nums.size();
    while (!nums.empty()) {
      cyclenum[nums.front()] = ct;
      nums.pop();
    }
    cyclelength[ct] = u;
    ++ct;
  }
  return n - ct;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
  }
  int m;
  cin >> m;
  int l = cyclestruct();
  if (m == l) {
    cout << '0' << endl;
    return 0;
  }
  if (m < l) {
    cout << l - m << endl;
    for (int i = 0; i < l - m; ++i) {
      int y = cyclestruct();
      for (int j = 1; j <= n; ++j) {
        if (cyclelength[cyclenum[j]] >= 2) {
          int min = 3005;
          int l = j;
          while (p[j] != l) {
            if (min > p[j]) min = p[j];
            j = p[j];
          }
          cout << l << ' ' << min << ' ';
          int o = p[l];
          p[l] = p[min];
          p[min] = o;
          break;
        }
      }
    }
  }
  if (m > l) {
    cout << m - l << endl;
    for (int i = 0; i < m - l; ++i) {
      int y = cyclestruct();
      for (int j = 2; j <= n; ++j) {
        if (cyclenum[j] != cyclenum[1]) {
          cout << '1' << ' ' << j << ' ';
          int o = p[1];
          p[1] = p[j];
          p[j] = o;
          break;
        }
      }
    }
  }
}
