#include <bits/stdc++.h>
using namespace std;
vector<int> graph[3010];
vector<int> con[3010];
int visited[3010], A[3010], ct = 0;
void dfs(int s) {
  visited[s] = 1;
  con[ct].push_back(s);
  for (int i = 0; i < graph[s].size(); i++) {
    if (!visited[graph[s][i]]) {
      dfs(graph[s][i]);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  int m;
  cin >> m;
  long long inv = 0;
  for (int i = 1; i <= n; i++) {
    graph[i].push_back(A[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      dfs(i);
      ct++;
    }
  }
  vector<pair<int, vector<int> > > df;
  for (int i = 0; i < ct; i++) {
    inv += con[i].size() - 1;
    df.push_back(make_pair(0, con[i]));
  }
  if (inv > m) {
    cout << inv - m << '\n';
    while (inv > m) {
      for (int i = 0; i < ct; i++) {
        sort(con[i].begin(), con[i].end());
      }
      for (int i = 0; i < ct; i++) {
        if (con[i].size() > 1) {
          cout << con[i][0] << " " << con[i][1] << '\n';
          swap(A[con[i][0]], A[con[i][1]]);
          break;
        }
      }
      for (int i = 0; i < 3010; i++) {
        con[i].clear();
        graph[i].clear();
      }
      for (int i = 1; i <= n; i++) {
        graph[i].push_back(A[i]);
      }
      memset(visited, 0, sizeof(visited));
      ct = 0;
      int cur = 0;
      for (int i = 1; i <= n; i++) {
        if (!visited[i]) {
          dfs(i);
          cur += con[ct].size() - 1;
          ct++;
        }
      }
      inv = cur;
    }
  } else if (inv < m) {
    int dif = m - inv;
    cout << m - inv << '\n';
    vector<int> temp;
    for (int i = 0; i < ct; i++) {
      temp.push_back(df[i].second[0]);
    }
    for (int i = 1; i < temp.size() && dif; i++, dif--) {
      cout << 1 << " " << temp[i] << ' ';
    }
  } else {
    cout << 0 << '\n';
  }
}
