#include <bits/stdc++.h>
using namespace std;
int n;
int p[3000 + 5];
vector<int> X;
void increase() {
  vector<int> vis(n), len(n + 1);
  int c = 0;
  for (int i = 0; i < n; ++i)
    if (!vis[i]) {
      int q = i;
      c++;
      while (!vis[q]) vis[q] = c, q = p[q], len[c]++;
    }
  int a = -1, b = -1;
  for (int i = 0; i < n; ++i)
    if (len[vis[i]] >= 2) {
      a = i;
      break;
    }
  for (int i = 0; i < n; ++i)
    if (vis[i] == vis[a] && i != a) {
      b = i;
      break;
    }
  X.push_back(a), X.push_back(b);
  int pa = p[a], push_back = p[b];
  p[b] = pa, p[a] = push_back;
}
void decrease() {
  vector<int> vis(n), len(n + 1);
  int c = 0;
  for (int i = 0; i < n; ++i)
    if (!vis[i]) {
      int q = i;
      c++;
      while (!vis[q]) vis[q] = c, q = p[q], len[c]++;
    }
  int a = 0, b = -1;
  for (int i = 0; i < n; ++i)
    if (vis[i] != vis[a] && i != a) {
      b = i;
      break;
    }
  X.push_back(a), X.push_back(b);
  int pa = p[a], push_back = p[b];
  p[b] = pa, p[a] = push_back;
}
int main() {
  int x, m;
  while (scanf("%d", &n) == 1) {
    for (int i = 0; i < n; ++i) {
      scanf("%d", &x);
      p[i] = --x;
    }
    scanf("%d", &m);
    int K = 0;
    vector<int> vis(n);
    for (int i = 0; i < n; ++i)
      if (!vis[i]) {
        int q = i;
        while (!vis[q]) vis[q] = 1, q = p[q];
        K++;
      }
    int target = n - m, tot = abs(K - target);
    X.clear();
    printf("%d\n", tot);
    if (K < target) {
      for (int i = 0; i < tot; ++i) increase();
    } else {
      for (int i = 0; i < tot; ++i) decrease();
    }
    for (int i = 0; i < ((int)X.size()); ++i)
      printf("%d%c", X[i] + 1, i + 1 == ((int)X.size()) ? 10 : 32);
  }
}
