#include <bits/stdc++.h>
using namespace std;
using ii = pair<long long int, long long int>;
const long long int N = 1e5 + 5;
bool chk = false, vis[N];
long long int g[N], in[N];
vector<long long int> from, to;
long long int n, cnt;
long long int dfs(long long int u) {
  vis[u] = 1;
  if (!vis[g[u]]) {
    return dfs(g[u]);
  }
  return u;
}
int32_t main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> g[i];
    in[g[i]]++;
  }
  for (long long int i = 1; i <= n; i++) {
    if (in[i] == 0) {
      chk = true;
      cnt++;
      from.push_back(i);
      to.push_back(dfs(i));
    }
  }
  for (long long int i = 1; i <= n; i++) {
    if (!vis[i]) {
      cnt++;
      from.push_back(i);
      to.push_back(dfs(i));
    }
  }
  if (!chk and cnt == 1) {
    cout << 0;
    return 0;
  }
  for (long long int i = 0; i < from.size(); i++) {
  }
  cout << cnt << "\n";
  for (long long int i = 0; i < cnt; i++) {
    cout << to[i] << " " << from[(i + 1) % cnt] << "\n";
  }
  return 0;
}
