#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9 + 7);
int n, m;
vector<int> per;
void cycles() {
  vector<int> aval;
  vector<int> glead;
  int ofp = 0;
  aval.assign(n + 1, true);
  for (int i = int(1); i <= int(n); ++i)
    if (aval[i]) {
      int next = per[i];
      aval[i] = false;
      while (next != i) {
        aval[next] = false;
        ++ofp, next = per[next];
      }
      glead.push_back(i);
    }
  int wanted = abs(ofp - m);
  printf("%d\n", wanted);
  if (ofp < m) {
    assert(wanted <= (int)glead.size() - 1);
    for (int i = int(1); i <= int(wanted); ++i)
      printf("%d %d ", glead[0], glead[i]);
    puts("");
  } else if (ofp > m) {
    for (int gr = 0; gr < int(wanted); ++gr) {
      int best1 = inf, best2 = inf;
      aval.assign(n + 1, true);
      for (int i = int(1); i <= int(n); ++i)
        if (aval[i]) {
          aval[i] = false;
          int next = per[i];
          if (next == i) continue;
          best1 = i, best2 = next;
          while (next != i) {
            best2 = min(best2, next);
            aval[next] = false;
            next = per[next];
          }
          break;
        }
      swap(per[best1], per[best2]);
      printf("%d %d ", best1, best2);
    }
    puts("");
  }
}
int main() {
  while (cin >> n) {
    per.resize(n + 1);
    for (int i = int(1); i <= int(n); ++i) scanf("%d", &per[i]);
    cin >> m;
    cycles();
  }
  return 0;
}
