#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int N = 1e5 + 7;
int n, tot;
int to[N], head[N], tail[N], du[N], pre[N];
int Dfs(int u) {
  if (pre[to[u]]) return pre[u] = u;
  pre[u] = 1;
  return pre[u] = Dfs(to[u]);
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) to[i] = read(), du[to[i]]++;
  for (int i = 1; i <= n; ++i)
    if (!du[i]) {
      head[++tot] = i;
      tail[tot] = Dfs(i);
    }
  int kk = tot;
  for (int i = 1; i <= n; ++i)
    if (!pre[i]) {
      head[++tot] = i;
      tail[tot] = Dfs(i);
    }
  if (!kk && tot == 1)
    puts("0");
  else {
    printf("%d\n", tot);
    for (int i = 1; i <= tot; ++i)
      printf("%d %d\n", tail[i], head[(i % tot) + 1]);
  }
  return 0;
}
