#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-8;
const double PI = acos(-1);
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
ostream &operator<<(ostream &o, const vector<T> &t) {
  o << '[';
  for (__typeof((t).begin()) i = (t).begin(); i != (t).end(); ++i) {
    if (i != t.begin()) o << ',';
    o << *i;
  }
  return o << ']';
}
template <class S, class T>
ostream &operator<<(ostream &o, const pair<S, T> &t) {
  return o << '(' << t.first << ',' << t.second << ')';
}
template <int N, class Tp>
void out(ostream &, const Tp &) {}
template <int N, class Tp, class, class... Ts>
void out(ostream &o, const Tp &t) {
  if (N) o << ',';
  o << get<N>(t);
  out<N + 1, Tp, Ts...>(o, t);
}
template <class... Ts>
ostream &operator<<(ostream &o, const tuple<Ts...> &t) {
  o << '(';
  out<0, tuple<Ts...>, Ts...>(o, t);
  return o << ')';
}
template <class T>
void output(T *a, int n) {
  for (int i = 0; i < (int)(n); ++i) {
    if (i) cout << ',';
    cout << a[i];
  }
  cout << endl;
}
template <class T>
void output(T *a, int n, int m) {
  for (int i = 0; i < (int)(n); ++i) output(a[i], m);
}
template <class T>
void output(T t) {
  if (t < 0) t = -t, putchar('-');
  static int c[20];
  int k = 0;
  while (t) c[k++] = t % 10, t /= 10;
  if (!k) c[k++] = 0;
  while (k) putchar(c[--k] ^ 48);
}
template <class S, class... T>
void output(S a, T... t) {
  output(a);
  putchar(' ');
  output(t...);
}
template <class T>
bool input(T &t) {
  t = 0;
  int n = 0, c;
  while (~(c = getchar()) && !isdigit(c) && c != '-')
    ;
  if (!~c) return 0;
  if (c == '-')
    n = 1;
  else
    t = c ^ 48;
  while (isdigit(c = getchar())) t = 10 * t + c - '0';
  t = n ? -t : t;
  return 1;
}
template <class S, class... T>
bool input(S &a, T &...t) {
  input(a);
  return input(t...);
}
int a[3000];
int cmp[3000];
int used[3000];
int main() {
  int n;
  while (input(n)) {
    for (int i = 0; i < (int)(n); ++i) {
      input(a[i]);
      a[i]--;
      cmp[i] = -1;
      used[i] = 0;
    }
    int m;
    input(m);
    int cnt = 0;
    for (int i = 0; i < (int)(n); ++i) {
      if (cmp[i] != -1) continue;
      cnt++;
      int c = i;
      do {
        cmp[c] = i;
        c = a[c];
      } while (c != i);
    }
    m = n - m;
    vector<pair<int, int> > ans;
    if (cnt > m) {
      for (int i = 0; i < (int)(n); ++i) {
        if (cmp[i] != 0 && !used[cmp[i]]) {
          used[cmp[i]] = 1;
          ans.push_back(pair<int, int>(0, i));
          cnt--;
          if (cnt == m) break;
        }
      }
    } else if (cnt < m) {
      int hoge = n;
      for (int i = 0; i < (int)(n); ++i) {
        for (int j = 0; j < (int)(n); ++j) {
          if (i == j) continue;
          if (cmp[i] == cmp[j]) {
            ans.push_back(pair<int, int>(i, j));
            cnt++;
            if (cnt == m) break;
            swap(a[i], a[j]);
            int s = i;
            do {
              cmp[s] = hoge;
              s = a[s];
            } while (s != i);
            hoge++;
          }
        }
        if (cnt == m) break;
      }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < (int)(ans.size()); ++i) {
      printf("%d %d ", ans[i].first + 1, ans[i].second + 1);
    }
    puts("");
  }
}
