#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * 1000 + 10;
int a[maxn], pos[maxn], par[maxn], t[maxn];
bool mark[maxn];
void dfs(int source, int parent) {
  mark[source] = true;
  par[source] = parent;
  t[parent]++;
  if (!mark[pos[source]]) dfs(pos[source], parent);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], pos[a[i]] = i;
  int m;
  cin >> m;
  int cur = 0;
  vector<int> P(0);
  for (int i = 1; i <= n; i++)
    if (!mark[i]) dfs(i, i), cur += t[i] - 1, P.push_back(i);
  vector<pair<int, int> > res(0);
  int ans = 0;
  if (cur < m)
    for (int i = 1; i < P.size() and cur < m; i++)
      ans++, cur++, res.push_back(make_pair(1, P[i]));
  else if (cur > m)
    while (cur > m)
      for (int i = 1; i <= n; i++)
        if (a[i] != i) {
          int id = a[i];
          int mini = id;
          while (id != i) mini = min(mini, id), id = a[id];
          res.push_back(make_pair(min(mini, i), max(i, mini)));
          swap(a[i], a[mini]);
          cur--;
          ans++;
          break;
        }
  cout << ans << endl;
  for (int i = 0; i < res.size(); i++)
    cout << res[i].first << " " << res[i].second << " ";
  cout << endl;
  return 0;
}
