#include <bits/stdc++.h>
using namespace std;
int find_father(vector<int>& f, int p) {
  if (f[p] == p) {
    return p;
  }
  return f[p] = find_father(f, f[p]);
}
int mark(vector<int>& f, vector<int>& ns, int p, int idx) {
  int cnt = 0;
  while (f[p] == -1) {
    f[p] = idx;
    p = ns[p];
    cnt++;
  }
  return cnt;
}
vector<int> solve(int n, vector<int>& ns, int m) {
  vector<int> f(n, -1);
  int idx = 0;
  int move = 0;
  for (int i = 0; i < n; i++) {
    if (f[i] == -1) {
      move += mark(f, ns, i, i) - 1;
    }
  }
  vector<int> res;
  while (move > m) {
    for (int i = 0; i < n; i++) {
      if (ns[i] == i) {
        continue;
      }
      vector<int> ps;
      int j = ns[i];
      while (j != i) {
        ps.push_back(j);
        j = ns[j];
      }
      sort(ps.begin(), ps.end());
      for (auto p : ps) {
        res.push_back(i);
        res.push_back(p);
        move--;
        swap(ns[i], ns[p]);
        break;
      }
      break;
    }
  }
  while (move < m) {
    for (int i = 1; i < n; i++) {
      if (find_father(f, 0) == find_father(f, i)) {
        continue;
      }
      res.push_back(0);
      res.push_back(i);
      move++;
      swap(ns[0], ns[i]);
      f[find_father(f, i)] = 0;
      break;
    }
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  vector<int> ns(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &ns[i]);
    ns[i] -= 1;
  }
  int m;
  cin >> m;
  auto res = solve(n, ns, m);
  int k = res.size();
  printf("%d\n", k / 2);
  for (int i = 0; i < k; i += 2) {
    printf("%d %d ", res[i] + 1, res[i + 1] + 1);
  }
  puts("");
  return 0;
}
