#include <bits/stdc++.h>
using namespace std;
const long long mx = 1e5 + 20;
long long to[mx], in[mx], ans, ans1, n, v;
bool visited[mx];
vector<long long> b, e;
long long dfs(long long u) {
  visited[u] = true;
  return visited[to[u]] ? u : dfs(to[u]);
}
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> v;
    to[i] = v;
    in[v]++;
  }
  for (long long i = 1; i <= n; i++) {
    if (!in[i]) {
      ans++;
      b.push_back(i);
      e.push_back(dfs(i));
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (!visited[i]) {
      ans1++;
      b.push_back(i);
      e.push_back(dfs(i));
    }
  }
  if (ans != 0 || ans1 != 1)
    ans += ans1;
  else
    ans = 0;
  cout << ans << "\n";
  for (long long i = 0; i < ans; i++) {
    cout << e[(i + 1) % ans] << " " << b[i] << "\n";
  }
  return 0;
}
