#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3 * 1000 + 10;
int mark[MAXN], out[MAXN], a[MAXN], sz = 0;
int num[MAXN];
vector<int> ans;
void dfs(int x, int col) {
  mark[x] = col;
  sz++;
  if (!mark[out[x]]) dfs(out[x], col);
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < (n); i++) cin >> a[i], a[i]--;
  int m;
  cin >> m;
  for (int i = 0; i < (n); i++) out[a[i]] = i;
  int cnt = 0, tot = 0;
  for (int i = 0; i < (n); i++)
    if (!mark[i]) {
      cnt++;
      sz = 0;
      dfs(i, cnt);
      tot += sz - 1;
      num[cnt] = sz;
    }
  while (tot < m) {
    for (int i = 1; i < n; i++)
      if (mark[0] != mark[i]) {
        swap(a[0], a[i]);
        ans.push_back(0);
        ans.push_back(i);
        break;
      }
    for (int i = 0; i < (n); i++) out[a[i]] = i;
    memset(mark, 0, sizeof mark);
    cnt = 0;
    tot++;
    for (int i = 0; i < (n); i++)
      if (!mark[i]) {
        cnt++;
        sz = 0;
        dfs(i, cnt);
      }
  }
  while (tot > m) {
    int start = 0;
    for (int i = 0; i < n; i++)
      if (num[mark[i]] > 1) {
        start = i;
        break;
      }
    for (int i = 0; i < n; i++)
      if (mark[start] == mark[i] && i != start) {
        swap(a[start], a[i]);
        ans.push_back(start);
        ans.push_back(i);
        break;
      }
    for (int i = 0; i < (n); i++) out[a[i]] = i;
    memset(mark, 0, sizeof mark);
    cnt = 0;
    tot--;
    for (int i = 0; i < (n); i++)
      if (!mark[i]) {
        cnt++;
        sz = 0;
        dfs(i, cnt);
        num[cnt] = sz;
      }
  }
  cout << ((int)(ans).size()) / 2 << endl;
  for (__typeof((ans).begin()) i = (ans).begin(); i != (ans).end(); i++)
    cout << *i + 1 << ' ';
  cout << endl;
  return 0;
}
