#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 2000000000;
const long long BIG = 1446803456761533460LL;
const int maxn = 3010;
int n, m, A[maxn], vis[maxn], cn;
vector<int> cyc[maxn];
vector<int> res;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> A[i], --A[i];
  cin >> m;
  for (int i = 0; i < n; ++i) {
    if (!vis[i]) {
      for (int x = i; !vis[x]; x = A[x]) cyc[cn].emplace_back(x), vis[x] = 1;
      ++cn;
    }
  }
  int f = n - cn;
  if (m < f) {
    for (int t = 0; t < f - m; ++t) {
      int i = 0;
      while (A[i] == i) ++i;
      int x = A[i];
      int mn = x;
      while (A[x] != i) {
        x = A[x];
        mn = min(mn, (x));
      }
      res.emplace_back(i), res.emplace_back(mn);
      swap(A[i], A[mn]);
    }
  } else if (m > f) {
    for (int i = 1; i < m - f + 1; ++i) {
      res.emplace_back(0), res.emplace_back(cyc[i][0]);
    }
  }
  cout << res.size() / 2 << '\n';
  for (auto a : res) cout << a + 1 << ' ';
  cout << '\n';
}
