#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int deg[maxn], n, rt;
vector<int> main_lamp;
int main() {
  scanf("%d", &n);
  scanf("%d", &rt);
  deg[rt]++;
  main_lamp.push_back(rt);
  for (int i = 2, x; i <= n - 1; i++) {
    scanf("%d", &x);
    deg[x]++;
    main_lamp.push_back(x);
  }
  priority_queue<int, vector<int>, greater<int> > q;
  for (int i = 1; i <= n; i++)
    if (deg[i] == 0) q.push(i);
  vector<pair<int, int> > ans;
  while (q.size()) {
    int x = q.top();
    q.pop();
    int y = main_lamp[main_lamp.size() - 1];
    main_lamp.pop_back();
    ans.push_back(make_pair(y, x));
    if (ans.size() == n - 1) break;
    deg[y]--;
    if (deg[y] == 0) q.push(y);
  }
  cout << rt << endl;
  for (int i = ans.size() - 1; i >= 0; i--)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
