#include <bits/stdc++.h>
using namespace std;
long long n, sr[200080], pr[200080], ptr;
int main() {
  scanf("%lld", &n);
  long long x, ok = 1, g;
  ptr = n;
  scanf("%lld", &x);
  g = x;
  sr[x] = 1;
  while (sr[ptr] && ptr > 0) ptr--;
  pr[ptr] = x;
  sr[ptr] = 1;
  for (int i = 2; i < n; i++) {
    scanf("%lld", &x);
    if (sr[x]) {
      while (sr[ptr] && ptr > 0) ptr--;
      if (ptr == 0) ok = 0;
      sr[ptr] = 1;
      pr[ptr] = x;
    } else {
      sr[x] = 1;
      pr[x] = pr[ptr];
      pr[ptr] = x;
    }
  }
  printf("%lld\n", g);
  for (int i = 1; i < n + 1; i++)
    if (pr[i]) printf("%d %lld\n", i, pr[i]);
}
