#include <bits/stdc++.h>
using namespace std;
vector<int> p, s, e;
int n;
int ind[100005], col[100005], adj[100005];
int dfs(int x) {
  col[x] = 1;
  int i = adj[x];
  if (!col[i])
    return col[x] = dfs(i);
  else
    return col[x] = x;
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &j), adj[i] = j, ind[j]++;
  k = 0;
  for (i = 1; i <= n; i++)
    if (!ind[i]) {
      e.push_back(i);
      s.push_back(dfs(i));
      k++;
    }
  j = k;
  for (i = 1; i <= n; i++)
    if (!col[i]) {
      e.push_back(i);
      s.push_back(dfs(i));
      k++;
    }
  if (k == 1 && j == 0)
    printf("0\n");
  else {
    printf("%d\n", k);
    for (i = 0; i < k; i++) printf("%d %d\n", s[i], e[(i + 1) % k]);
  }
  return 0;
}
