#include <bits/stdc++.h>
using namespace std;
int n;
int f[100010];
bitset<100010> deg;
bitset<100010> viz;
vector<pair<int, int> > c;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &f[i]);
    deg[f[i]] = 1;
  }
  int x;
  for (int i = 1; i <= n; ++i) {
    if (deg[i] == 1) continue;
    x = i;
    while (viz[x] == 0) {
      viz[x] = 1;
      x = f[x];
    }
    c.push_back(make_pair(i, x));
  }
  bool zero = c.empty();
  for (int i = 1; i <= n; ++i) {
    if (viz[i] == 1) continue;
    x = i;
    while (viz[x] == 0) {
      viz[x] = 1;
      x = f[x];
    }
    c.push_back(make_pair(i, i));
  }
  if (zero && c.size() == 1) {
    printf("0\n");
    return 0;
  }
  printf("%u\n", c.size());
  c.push_back(c[0]);
  size_t lim = c.size();
  for (size_t i = 1; i < lim; ++i)
    printf("%d %d\n", c[i - 1].second, c[i].first);
  return 0;
}
