#include <bits/stdc++.h>
using namespace std;
int power(int a, int b, int m = 1000000007) {
  if (b == 0) return 1;
  if (b == 1) return a;
  int res = power(a, b / 2, m);
  res = (res * res) % m;
  if (b & 1) res = (res * a) % m;
  return res;
}
int modinv(int a, int m = 1000000007) { return power(a, m - 2, m); }
int add(int a, int b, int m = 1000000007) {
  int c = (a % m + b % m);
  if (c >= m) c -= m;
  return c;
}
int sub(int a, int b, int m = 1000000007) {
  int c = (a % m - b % m);
  if (c < 0) c += m;
  return c;
}
int mul(int a, int b, int m = 1000000007) { return (a * b) % m; }
void solve() {
  int n;
  cin >> n;
  int a[n], vis[n], i, j, k = 0, m;
  memset(vis, 0, sizeof(vis));
  for (i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  cin >> m;
  for (i = 0; i < n; i++) {
    if (vis[i]) continue;
    j = i;
    while (!vis[j]) {
      vis[j] = 1;
      j = a[j];
    }
    k++;
  }
  m = n - m;
  cout << abs(m - k) << "\n";
  memset(vis, 0, sizeof(vis));
  if (k > m) {
    j = 0;
    while (!vis[j]) {
      vis[j] = 1;
      j = a[j];
    }
    for (i = 1; i < n && k > m; i++) {
      if (vis[i]) continue;
      j = i;
      k--;
      cout << "1 " << i + 1 << " ";
      while (!vis[j]) {
        vis[j] = 1;
        j = a[j];
      }
    }
  }
  if (k < m) {
    for (i = 0; i < n, k < m; i++) {
      vector<int> pos(n, -1);
      int cur = 0;
      for (j = a[i]; j != i; j = a[j]) pos[j] = cur++;
      pos[i] = cur;
      cur = 0;
      for (j = i + 1; j < n && k < m; j++) {
        if (pos[j] >= cur) {
          cout << i + 1 << " " << j + 1 << " ";
          k++;
          cur = pos[j] + 1;
          swap(a[i], a[j]);
        }
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
