#include <bits/stdc++.h>
using namespace std;
int a[3010], id[3010], num[3010];
vector<int> ans;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int m;
  scanf("%d", &m);
  int need = n - m;
  while (true) {
    int tot = 0;
    memset(id, -1, sizeof(id));
    memset(num, 0, sizeof(num));
    for (int i = 1; i <= n; i++) {
      if (id[i] == -1) {
        id[i] = tot;
        int now = a[i];
        while (now != i) {
          id[now] = tot;
          now = a[now];
        }
        tot++;
      }
    }
    for (int i = 1; i <= n; i++) {
      num[id[i]]++;
    }
    if (tot == need) break;
    if (tot > need) {
      for (int i = 2; i <= n; i++) {
        if (id[i] != id[1]) {
          ans.push_back(1);
          ans.push_back(i);
          swap(a[1], a[i]);
          break;
        }
      }
    } else {
      for (int i = 1; i <= n; i++) {
        if (num[id[i]] == 1) continue;
        for (int j = i + 1; j <= n; j++) {
          if (id[i] == id[j]) {
            ans.push_back(i);
            ans.push_back(j);
            swap(a[i], a[j]);
            break;
          }
        }
        break;
      }
    }
  }
  printf("%d\n", ans.size() / 2);
  for (int i = 0; i < ans.size(); i++) {
    if (i) printf(" ");
    printf("%d", ans[i]);
  }
  puts("");
  return 0;
}
