#include <bits/stdc++.h>
const int INF = 0x7F7F7F7F;
const double EPS = 1e-10;
const long long mod7 = 1e9 + 7;
const long long mod9 = 1e9 + 9;
using namespace std;
inline long long rit() {
  long long f = 0, key = 1;
  char c;
  do {
    c = getchar();
    if (c == '-') key = -1;
  } while (c < '0' || c > '9');
  do {
    f = f * 10 + c - '0';
    c = getchar();
  } while (c >= '0' && c <= '9');
  return f * key;
}
inline void fprt(double f) { printf("%.08lf", f); }
void init() {}
const int Z = 3005;
int n, m;
int p[Z], rt[Z], cnt;
int lst[Z];
vector<pair<int, int> > pv;
int findroot(int x) {
  if (rt[x] == x) return x;
  return rt[x] = findroot(rt[x]);
}
void Union(int a, int b) {
  a = findroot(a);
  b = findroot(b);
  if (a != b) {
    cnt++;
    rt[a] = b;
  }
}
void build() {
  for (int i = 1; i <= n; ++i) rt[i] = i;
  cnt = 0;
  for (int i = 1; i <= n; ++i) {
    lst[i] = -1;
    Union(i, p[i]);
  }
}
void read() {
  n = rit();
  for (int i = 1; i <= n; ++i) {
    p[i] = rit();
  }
  m = rit();
}
void solve() {
  int f;
  pair<int, int> ans;
  do {
    build();
    if (cnt > m) {
      for (int i = n; i >= 1; --i) {
        f = findroot(i);
        if (lst[f] != -1) {
          ans = make_pair(i, lst[f]);
        }
        lst[f] = i;
      }
      pv.push_back(ans);
      swap(p[ans.first], p[ans.second]);
    } else if (cnt < m) {
      f = findroot(1);
      for (int i = 1; i <= n; ++i) {
        if (findroot(i) != f) {
          ans = make_pair(1, i);
          break;
        }
      }
      pv.push_back(ans);
      swap(p[ans.first], p[ans.second]);
    }
  } while (cnt != m);
  printf("%d\n", (int)((pv).size()));
  for (auto f : pv) printf("%d %d ", f.first, f.second);
  printf("\n");
}
int main() {
  int nn = 1;
  while (nn--) {
    init(), read(), solve();
  }
  return 0;
}
