#include <bits/stdc++.h>
using namespace std;
int n, m, i, now, a[3010], vis[3010];
vector<pair<int, int> > ans;
void zh() {
  int i, tem, j, st = 0;
  memset(vis, 0, sizeof(vis));
  for (i = 1; i <= n; i++)
    if (!vis[i]) {
      vis[i] = ++st;
      tem = 1;
      for (j = a[i]; !vis[j]; j = a[j]) tem++, vis[j] = st;
      now += tem - 1;
    }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  while (1) {
    now = 0;
    zh();
    if (m == now) break;
    if (m > now) {
      for (i = 2; i <= n; i++)
        if (vis[i] != vis[1]) {
          swap(a[i], a[1]);
          ans.push_back(make_pair(1, i));
          break;
        }
    } else {
      for (i = 1; i <= n; i++)
        if (a[i] != i) break;
      int z = 3010;
      for (int o = a[i]; o != i; o = a[o]) z = min(o, z);
      ans.push_back(make_pair(i, z));
      swap(a[i], a[z]);
    }
  }
  printf("%d\n", ans.size());
  for (i = 0; i < ans.size(); i++)
    printf("%d %d ", ans[i].first, ans[i].second);
  return 0;
}
