#include <bits/stdc++.h>
using namespace std;
using pii = pair<long long int, long long int>;
using vi = vector<long long int>;
using vpii = vector<pii>;
using G = vector<vi>;
using WG = vector<vpii>;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const long long int INF = 0x3f3f3f3f;
const long long int mod1 = 1e9 + 7;
const long long int mod2 = 1e9 + 9;
const long long int b = 32;
const long long int MAXN = 2e5 + 2;
int32_t main() {
  ios::sync_with_stdio(0);
  long long int n;
  cin >> n;
  vi arr(n - 1), freq(n + 1);
  for (long long int& x : arr) {
    cin >> x;
    ++freq[x];
  }
  priority_queue<pii> leafs;
  vi c(n + 1);
  for (long long int i = 1; i <= n; ++i) {
    c[i] = i;
    if (freq[i] == 0) {
      leafs.emplace(-i, i);
    }
  }
  vi p(n + 1);
  for (long long int i = n - 2; i >= 0; --i) {
    long long int u;
    u = leafs.top().second;
    leafs.pop();
    p[u] = arr[i];
    c[arr[i]] = max(c[arr[i]], c[u]);
    if (--freq[arr[i]] == 0) {
      leafs.emplace(-c[arr[i]], arr[i]);
    }
  }
  long long int root;
  G g(n + 1);
  for (long long int i = 1; i <= n; ++i) {
    if (p[i] == 0) {
      root = i;
    } else {
      g[p[i]].push_back(i);
    }
  }
  priority_queue<pii> pq;
  pq.emplace(root, root);
  long long int cur = 0;
  while (pq.size()) {
    long long int u;
    u = pq.top().second;
    pq.pop();
    if (u != root && arr[cur++] != p[u]) {
      return cout << "-1\n", 0;
    }
    for (long long int v : g[u]) {
      pq.emplace(c[v], v);
    }
  }
  cout << root << '\n';
  for (long long int i = 1; i <= n; ++i) {
    for (long long int x : g[i]) {
      cout << i << ' ' << x << '\n';
    }
  }
}
