#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e3 + 3;
int p[MAX], cycle[MAX], nocycles, n, m;
void dfs(int v) {
  cycle[v] = nocycles;
  if (cycle[p[v]] == 0) dfs(p[v]);
}
void gen() {
  nocycles = 1;
  memset(cycle, 0, sizeof cycle);
  for (int i = 1; i < n + 1; i++)
    if (not cycle[i]) dfs(i), nocycles++;
}
vector<pair<int, int> > ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", p + i);
  }
  cin >> m;
  gen();
  int cur = n - nocycles + 1;
  if (cur < m) {
    int idx = 2;
    while (cur != m) {
      int comp = cycle[p[idx]];
      if (comp == cycle[p[1]]) {
        idx++;
        continue;
      }
      ans.push_back(pair<int, int>(1, idx));
      for (int i = idx; i < n + 1; i++)
        if (cycle[i] == comp) cycle[i] = cycle[p[1]];
      cur++, idx++;
    }
  } else if (cur > m) {
    int idx = 1, loop = 1;
    while (cur != m) {
      if (p[idx] == idx) {
        idx++;
        continue;
      }
      for (int i = idx + 1; i < n + 1; i++)
        if (cycle[p[i]] == cycle[p[idx]]) {
          ans.push_back(pair<int, int>(idx, i));
          swap(p[idx], p[i]);
          break;
        }
      cur--;
      gen();
      loop++;
      assert(loop <= n + 10);
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d ", ans[i].first, ans[i].second);
  }
  cout << endl;
  return 0;
}
