#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
  return out << "(" << pair.first << ", " << pair.second << ")";
}
int N;
int in[3005];
int groups[3005];
int gg = 0;
vector<pair<int, int> > ans;
int dfs(int at) {
  groups[at] = gg;
  if (groups[in[at]] == gg) return 0;
  return 1 + dfs(in[at]);
}
int min_swaps = 0;
int M;
void solve(int at) {
  int p = 0;
  for (int j = 1; j <= N; j++) {
    if (in[j] == at) {
      p = j;
      break;
    }
  }
  if (min(at, in[at]) < min(at, p) ||
      (min(at, in[at]) == min(at, p) && max(at, in[at]) < max(at, p))) {
    ans.push_back(pair<int, int>(min(at, in[at]), max(at, in[at])));
    swap(in[at], in[in[at]]);
    min_swaps--;
  } else {
    ans.push_back(pair<int, int>(min(at, p), max(at, p)));
    swap(in[at], in[p]);
    min_swaps--;
  }
}
bool mark[3005];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &in[i]);
  for (int i = 1; i <= N; i++) {
    if (groups[i] == 0) {
      gg++;
      min_swaps += dfs(i);
    }
  }
  scanf("%d", &M);
  if (M == min_swaps) {
    printf("0\n");
  } else if (M < min_swaps) {
    while (min_swaps != M) {
      memset(groups, 0, sizeof(groups));
      for (int i = 1; i <= N; i++) {
        if (groups[i] == 0) {
          gg++;
          dfs(i);
        }
      }
      int a, b;
      for (int i = 1; i <= N; i++) {
        if (in[i] != i) {
          a = i;
          for (int j = 1; j <= N; j++) {
            if (j != a && groups[a] == groups[j]) {
              b = j;
              break;
            }
          }
          break;
        }
      }
      ans.push_back(pair<int, int>(min(a, b), max(a, b)));
      swap(in[a], in[b]);
      min_swaps--;
    }
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); i++)
      cout << ans[i].first << " " << ans[i].second << endl;
  } else {
    int cnt = M - min_swaps;
    mark[groups[1]] = true;
    for (int i = 2; i <= N && cnt; i++) {
      if (mark[groups[i]] == false) {
        ans.push_back(pair<int, int>(1, i));
        mark[groups[i]] = true;
        cnt--;
      }
    }
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); i++)
      cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
