#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-7;
const int MAX_N = 3000;
int data[MAX_N + 5];
int N, M;
int comp[MAX_N + 5];
int cost() {
  int ret = 0;
  vector<int> v(data, data + N);
  for (int(i) = 0, (_batas) = (N); (i) < (_batas); (i)++) {
    while (v[i] != i + 1) {
      swap(v[i], v[v[i] - 1]);
      ret++;
    }
  }
  return ret;
}
void buildComp() {
  memset(comp, -1, sizeof comp);
  vector<int> v(data, data + N);
  int ncomp = 0;
  for (int(i) = 0, (_batas) = (N); (i) < (_batas); (i)++) {
    int curr = i;
    while (comp[curr] == -1) {
      comp[curr] = ncomp;
      curr = v[curr] - 1;
    }
    ncomp++;
  }
}
int main() {
  scanf("%d", &N);
  for (int(i) = 0, (_batas) = (N); (i) < (_batas); (i)++) scanf("%d", &data[i]);
  scanf("%d", &M);
  vector<int> ans;
  int currCost = cost();
  while (currCost != M) {
    buildComp();
    if (currCost < M) {
      int anyPos = 0;
      for (int(i) = 0, (_batas) = (N); (i) < (_batas); (i)++)
        if (i != anyPos && comp[i] != comp[anyPos]) {
          swap(data[anyPos], data[i]);
          ans.push_back(anyPos);
          ans.push_back(i);
          break;
        }
      currCost++;
    } else {
      int badPos = -1;
      for (int(i) = 0, (_batas) = (N); (i) < (_batas); (i)++)
        if (data[i] != i + 1) {
          badPos = i;
          break;
        }
      for (int(i) = 0, (_batas) = (N); (i) < (_batas); (i)++)
        if (i != badPos && comp[badPos] == comp[i]) {
          swap(data[badPos], data[i]);
          ans.push_back(min(badPos, i));
          ans.push_back(max(badPos, i));
          break;
        }
      currCost--;
    }
  }
  printf("%d\n", ((int)(ans).size()) / 2);
  for (int(i) = 0, (_batas) = (((int)(ans).size())); (i) < (_batas); (i)++) {
    printf("%d", ans[i] + 1);
    if (i < ((int)(ans).size()) - 1)
      printf(" ");
    else
      puts("");
  }
  assert(cost() == M);
  return 0;
}
