#include <bits/stdc++.h>
using namespace std;
bool was[120000];
int n;
int st[120000], en[120000];
int k = 0;
int f[120000], num[120000];
void go(int x) {
  was[x] = true;
  if (!was[f[x]])
    go(f[x]);
  else
    en[k] = f[x];
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
    num[f[i]]++;
  }
  for (int i = 1; i <= n; i++)
    if (num[i] == 0) {
      st[k] = i;
      go(i);
      k++;
    }
  for (int i = 1; i <= n; i++)
    if (!was[i]) {
      st[k] = i;
      en[k] = i;
      go(i);
      k++;
    }
  if (k == 1 && st[k - 1] == en[k - 1]) k = 0;
  cout << k << endl;
  for (int i = 0; i < k; i++) {
    cout << en[(i + 1) % k] << " " << st[i] << endl;
  }
  return 0;
}
