#include <bits/stdc++.h>
using namespace std;
int n, a[100005], __start[100005], __end[100005], cc;
bool vis[100005], in[100005];
void dfs(int s) {
  if (vis[s]) return;
  vis[s] = 1;
  __end[cc] = s;
  dfs(a[s]);
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    in[a[i]] = 1;
  }
  bool ok = 0;
  for (int i = 1; i <= n; i++) {
    if (in[i]) continue;
    ok = 1;
    __start[cc] = i;
    dfs(i);
    cc++;
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    __start[cc] = i;
    dfs(i);
    cc++;
  }
  if (cc == 1 && !ok)
    cout << "0\n";
  else {
    cout << cc << "\n";
    for (int i = 0; i < cc; i++) {
      cout << __end[i] << " " << __start[(i + 1) % cc] << "\n";
    }
  }
  return 0;
}
