#include <bits/stdc++.h>
using namespace std;
int n, p[3333], m, c[3333], s[3333];
vector<int> ans(0);
int get_cycles() {
  memset(c, -1, sizeof(c));
  memset(s, 0, sizeof(s));
  int k = 0;
  for (int i = 0; i < n; ++i) {
    if (c[i] == -1) {
      int first = i;
      do {
        c[first] = k;
        s[k]++;
        first = p[first];
      } while (c[first] == -1);
      ++k;
    }
  }
  return k;
}
vector<int> solve() {
  ans.clear();
  while (1) {
    int k = get_cycles();
    if (k + m == n) break;
    if (k + m < n) {
      int fst = 0;
      while (s[c[fst]] == 1) ++fst;
      for (int j = fst + 1; j < n; ++j) {
        if (c[j] == c[fst]) {
          ans.push_back(fst);
          ans.push_back(j);
          swap(p[j], p[fst]);
          break;
        }
      }
    } else {
      for (int j = 1; j < n; ++j) {
        if (c[j] != c[0]) {
          ans.push_back(0);
          ans.push_back(j);
          swap(p[j], p[0]);
          break;
        }
      }
    }
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &p[i]);
    --p[i];
  }
  scanf("%d", &m);
  vector<int> ans = solve();
  cout << ((int)(ans).size()) / 2 << endl;
  for (int i = 0; i < ((int)(ans).size()); ++i) {
    if (i) cout << " ";
    cout << ans[i] + 1;
  }
  cout << endl;
}
