#include <bits/stdc++.h>
int main() {
  static char used[200000 + 1];
  int n, p, x;
  scanf("%d%d", &n, &p);
  used[p] = 1, printf("%d\n", p);
  x = n;
  for (n -= 2; n; n--) {
    int i;
    scanf("%d", &i);
    if (used[i]) {
      while (used[x]) x--;
      used[x] = 1, printf("%d %d\n", p, x);
    } else
      used[i] = 1, printf("%d %d\n", p, i);
    p = i;
  }
  while (used[x]) x--;
  used[x] = 1, printf("%d %d\n", p, x);
  return 0;
}
