#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1;
const int INF = 1e9 + 7;
int p[maxn];
bool used[maxn];
void dfs(int v) {
  for (int i = v; !used[i]; i = p[i]) used[i] = true;
}
int main() {
  int n;
  cin >> n;
  int col = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
  }
  int m;
  cin >> m;
  for (int i = 1; i <= n; ++i) {
    if (!used[i]) {
      dfs(i);
      ++col;
    }
  }
  m = n - m;
  cout << abs(col - m) << "\n";
  for (int i = 1; i <= n; ++i) used[i] = false;
  if (col > m) {
    dfs(1);
    for (int i = 2; i <= n && col > m; ++i) {
      if (!used[i]) {
        cout << 1 << " " << i << " ";
        dfs(i);
        col--;
      }
    }
  } else {
    for (int i = 1; i <= n && col < m; ++i) {
      vector<int> pos(n + 1, -1);
      int cur = 0;
      for (int j = p[i]; j != i; j = p[j]) pos[j] = cur++;
      pos[i] = cur;
      cur = 0;
      for (int j = i + 1; j <= n; ++j) {
        if (pos[j] >= cur) {
          cout << i << " " << j << " ";
          swap(p[i], p[j]);
          cur = pos[j] + 1;
          col++;
          if (col == m) break;
        }
      }
    }
  }
}
