#include <bits/stdc++.h>
using namespace std;
int a[3004];
int vis[3004];
int main() {
  int n, m;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> m;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      vis[i] = ++cnt;
      int l = i;
      while (!vis[a[l]]) {
        vis[a[l]] = cnt;
        l = a[l];
      }
    }
  }
  cout << abs(n - m - cnt) << endl;
  if (n - m - cnt < 0) {
    for (int i = 0; i < abs(n - m - cnt); i++) {
      for (int j = 2; j <= n; j++) {
        if (vis[1] != vis[j]) {
          swap(a[1], a[j]);
          int cnt = 0;
          memset(vis, 0, sizeof(vis));
          for (int k = 1; k <= n; k++) {
            if (!vis[k]) {
              vis[k] = ++cnt;
              int l = k;
              while (!vis[a[l]]) {
                vis[a[l]] = cnt;
                l = a[l];
              }
            }
          }
          cout << 1 << " " << j << " ";
          break;
        }
      }
    }
  } else {
    for (int i = 0; i < abs(n - m - cnt); i++) {
      int cnt = 0, id;
      for (int j = 1; j <= n; j++) {
        if (cnt == 0 && a[j] != j) {
          cnt++;
          id = j;
        } else if (cnt == 1 && vis[id] == vis[j]) {
          swap(a[id], a[j]);
          cout << id << " " << j << " ";
          int cnt = 0;
          memset(vis, 0, sizeof(vis));
          for (int k = 1; k <= n; k++) {
            if (!vis[k]) {
              vis[k] = ++cnt;
              int l = k;
              while (!vis[a[l]]) {
                vis[a[l]] = cnt;
                l = a[l];
              }
            }
          }
          break;
        }
      }
    }
  }
}
