import java.io.*;
import java.math.BigInteger;
import java.util.*;

// written by luchy0120

public class Main {
    public static void main(String[] args) throws Exception {

        new Main().run();
    }

    static int groups = 0;
    static int[] fa;
    static int[] sz;

    static void init(int n) {
        groups = n;
        fa = new int[n];
        for (int i = 1; i < n; ++i) {
            fa[i] = i;
        }
        sz = new int[n];
        Arrays.fill(sz, 1);
    }

    static int root(int p) {
        while (p != fa[p]) {
            fa[p] = fa[fa[p]];
            p = fa[p];
        }
        return p;
    }

    static void combine(int p, int q) {
        int i = root(p);
        int j = root(q);
        if (i == j) {
            return;
        }
        if (sz[i] < sz[j]) {
            fa[i] = j;
            sz[j] += sz[i];
        } else {
            fa[j] = i;
            sz[i] += sz[j];
        }
        groups--;
    }

    int color[],dfn[],low[],stack[],cnt[];
    boolean vis[];
    boolean iscut[];
    int deep,top,n,m,sum,ans;
    List<Integer> g[];

    void tarjan(int u,int fa) {
        int child = 0;
        dfn[u]=++deep;
        low[u]=deep;
        vis[u]=true;
        stack[++top]=u;
        int sz=g[u].size();
        for(int i=0;i<sz;i++) {
            int v =g[u].get(i);
            if(v==fa) continue;
            if(dfn[v]==0) {
                child++;
                tarjan(v,u);
                low[u]=Math.min(low[u],low[v]);
            } else {
                if(vis[v]) {
                    low[u]=Math.min(low[u],low[v]);
                }
            }
        }
        if(fa<0&&child==1){
            iscut[u] =true;
        }

        if(dfn[u]==low[u]) {
            iscut[u] = true;
            color[u]=++sum;
            vis[u]=false;
            while(stack[top]!=u) {
                color[stack[top]]=sum;
                vis[stack[top--]]=false;
            }
            top--;
        }
    }

    int h[],to[],ne[];int ct =0;
    void add(int u,int v){
        u--;v--;
        to[ct] = v;
        ne[ct] = h[u];
        h[u] = ct++;
    }

    void graph(int n,int m){
        h = new int[n];
        Arrays.fill(h,-1);
        ne = new int[2*m];
        to = new int[2*m];
        ct = 0;
    }

    static long mul(long a, long b, long p)
    {
        long res=0,base=a;
        while(b>0)
        {
            if((b&1L)>0)
                res=(res+base)%p;
            base=(base+base)%p;
            b>>=1;
        }
        return res;
    }

    static long mod_pow(long k,long n,long p){
        long res = 1L;
        long temp = (k%p+p)%p;
        while(n!=0L){
            if((n&1L)==1L){
                res = ((res*temp)%p+p)%p;
            }
            temp = ((temp * temp)%p+p)%p;
            n = n>>1L;
        }
        return res%p;
    }
    public static String roundS(double result, int scale){
        String fmt = String.format("%%.%df", scale);
        return String.format(fmt, result);
    }

    int x[];
    int y[];
    int k ;
    int r = 1000000000;
    int[][] pos;

    boolean gd(int i){
        if(pos[i][0]<pos[i][1]) return false;
        if(pos[i][2]>pos[i][3]) return false;
        return true;
    }

    int area(int i){
        if(pos[i][0]<=pos[i][1]) return 0;
        if(pos[i][2]>=pos[i][3]) return 0;
        return (pos[i][0]-pos[i][1])*(pos[i][3]-pos[i][2]);
    }

    boolean in(int i,int y,int x){
        return y<=pos[i][0]&&y>=pos[i][1] && x<=pos[i][3] && x>= pos[i][2];
    }

    boolean ck(int i,int j){
        return !in(i, pos[j][0],pos[j][3]) &&
        !in(i, pos[j][0],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][3]);
    }

    void go(int c,int sum){
        if(sum>=r) return;
        if(c==n){
            for(int i=0;i<k;++i) {
                if (!gd(i)) return;
            }

            for(int i=0;i<k;++i){
                for(int j=i+1;j<k;++j){
                    if(!ck(i,j)){
                        return;
                    }
                }
            }
            r = sum;
            return;
        }

        for(int i=0;i<k;++i){
            int tmp[] = pos[i].clone();
            int zx = x[c];
            int zy = y[c];

            int prev = area(i);

            pos[i][0] = Math.max(pos[i][0],zy);
            pos[i][1] = Math.min(pos[i][1],zy);

            pos[i][2] = Math.min(pos[i][2],zx);
            pos[i][3] = Math.max(pos[i][3],zx);

            int cur = area(i);

            go(c+1,sum-prev+cur);

            pos[i] = tmp;
        }

    }

    int dx[] = {0,0,1,-1};
    int dy[] = {1,-1,0,0};
    boolean xiao(int mp[][]){
        boolean ok = false;
        boolean mk[][] = new boolean[7][5];
        for(int i=0;i<7;++i){
            for(int j=0;j<5;++j){
                if(mp[i][j]==0) continue;
                int k = j+1;
                int c = mp[i][j];
                while(k<5&&mp[i][k]==c) k++;
                if(k-j>=3){
                    ok = true;
                    for(int u=j;u<k;++u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<5;++i){
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) break;
                int k = j-1;
                int c = mp[i][j];
                while(k>=0&&mp[i][k]==c) k--;
                if(j-k>=3){
                    ok = true;
                    for(int u=j;u>k;--u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<7;++i) {
            for (int j = 0; j < 5; ++j) {
                if (mp[i][j] > 0 && mk[i][j]) {
                    mp[i][j] = 0;
                }
            }
        }
      return ok;
    }

    void luo(int[][] mp){
        for(int i=0;i<5;++i){
            int f = 6;
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) continue;
                mp[i][f] = mp[i][j];f--;
                mp[i][j] = 0;
            }
        }
    }

    void go(int mp[][]){

        while(xiao(mp)){
            luo(mp);
        }

    }

    void sort(int a[]){
        Arrays.sort(a);
    }

    int gcd(int a,int b){
        return b==0?a:gcd(b,a%b);
    }

    void solve() {
//        int n = ni();
//        int mp[][] = new int[7][5];
//        // less than 10;
//
//        for(int i=0;i<5;++i){
//            int x = 6;
//            while(true){
//                int num = ni();
//                if(num==0) break;
//                mp[x][i] = num;
//                x--;
//            }
//        }

            int n = ni();

            int cur = ni();
            StringBuilder sb  =new StringBuilder();
            sb.append(cur+"\n");
            boolean vis[] = new boolean[n+1];
            vis[cur] = true;

        int ma = n;
        if(ma==cur){
            ma--;
        }
        for(int i=0;i<n-2;++i){
                int v = ni();
                if(!vis[v]){
                    sb.append(cur+" "+v+"\n");
                    vis[v] = true;
                    cur = v;
                    if(v==ma){
                        ma--;
                    }
                }else{
                    while(vis[ma]) ma--;
                    sb.append(cur+" "+ma+"\n");
                    vis[ma] = true;
                    ma--;
                    cur = v;
                }
            }
        while(vis[ma]) ma--;
        sb.append(cur+" "+ma+"\n");
        println(sb);

//            init(n+1);
//            for(int i=1;i<=n;++i){
//                for(int go:ch[i]){
//                    if(root(go)==root(i)){
//                        println(-1); return;
//                    }
//                    combine(go,i);
//                }
//            }

//                println(root);
//                for(int i=1;i<=n;++i){
//                    for(int go:ch[i]){
//                        println(go+" "+i);
//                    }
//                }
//

    }

    InputStream is;
    PrintWriter out;

    void run() throws Exception {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private char ncc() {
        int b = readByte();
        return (char) b;
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private String nline() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!isSpaceChar(b) || b == ' ') {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[][] nm(int n, int m) {
        char[][] a = new char[n][];
        for (int i = 0; i < n; i++) a[i] = ns(m);
        return a;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private long[] nal(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nl();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = num * 10 + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    void print(Object obj) {
        out.print(obj);
    }

    void println(Object obj) {
        out.println(obj);
    }

    void println() {
        out.println();
    }

    void printArray(int a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }

    void printArray(long a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

// written by luchy0120

public class Main {
    public static void main(String[] args) throws Exception {

        new Main().run();
    }

    static int groups = 0;
    static int[] fa;
    static int[] sz;

    static void init(int n) {
        groups = n;
        fa = new int[n];
        for (int i = 1; i < n; ++i) {
            fa[i] = i;
        }
        sz = new int[n];
        Arrays.fill(sz, 1);
    }

    static int root(int p) {
        while (p != fa[p]) {
            fa[p] = fa[fa[p]];
            p = fa[p];
        }
        return p;
    }

    static void combine(int p, int q) {
        int i = root(p);
        int j = root(q);
        if (i == j) {
            return;
        }
        if (sz[i] < sz[j]) {
            fa[i] = j;
            sz[j] += sz[i];
        } else {
            fa[j] = i;
            sz[i] += sz[j];
        }
        groups--;
    }

    int color[],dfn[],low[],stack[],cnt[];
    boolean vis[];
    boolean iscut[];
    int deep,top,n,m,sum,ans;
    List<Integer> g[];

    void tarjan(int u,int fa) {
        int child = 0;
        dfn[u]=++deep;
        low[u]=deep;
        vis[u]=true;
        stack[++top]=u;
        int sz=g[u].size();
        for(int i=0;i<sz;i++) {
            int v =g[u].get(i);
            if(v==fa) continue;
            if(dfn[v]==0) {
                child++;
                tarjan(v,u);
                low[u]=Math.min(low[u],low[v]);
            } else {
                if(vis[v]) {
                    low[u]=Math.min(low[u],low[v]);
                }
            }
        }
        if(fa<0&&child==1){
            iscut[u] =true;
        }

        if(dfn[u]==low[u]) {
            iscut[u] = true;
            color[u]=++sum;
            vis[u]=false;
            while(stack[top]!=u) {
                color[stack[top]]=sum;
                vis[stack[top--]]=false;
            }
            top--;
        }
    }

    int h[],to[],ne[];int ct =0;
    void add(int u,int v){
        u--;v--;
        to[ct] = v;
        ne[ct] = h[u];
        h[u] = ct++;
    }

    void graph(int n,int m){
        h = new int[n];
        Arrays.fill(h,-1);
        ne = new int[2*m];
        to = new int[2*m];
        ct = 0;
    }

    static long mul(long a, long b, long p)
    {
        long res=0,base=a;
        while(b>0)
        {
            if((b&1L)>0)
                res=(res+base)%p;
            base=(base+base)%p;
            b>>=1;
        }
        return res;
    }

    static long mod_pow(long k,long n,long p){
        long res = 1L;
        long temp = (k%p+p)%p;
        while(n!=0L){
            if((n&1L)==1L){
                res = ((res*temp)%p+p)%p;
            }
            temp = ((temp * temp)%p+p)%p;
            n = n>>1L;
        }
        return res%p;
    }
    public static String roundS(double result, int scale){
        String fmt = String.format("%%.%df", scale);
        return String.format(fmt, result);
    }

    int x[];
    int y[];
    int k ;
    int r = 1000000000;
    int[][] pos;

    boolean gd(int i){
        if(pos[i][0]<pos[i][1]) return false;
        if(pos[i][2]>pos[i][3]) return false;
        return true;
    }

    int area(int i){
        if(pos[i][0]<=pos[i][1]) return 0;
        if(pos[i][2]>=pos[i][3]) return 0;
        return (pos[i][0]-pos[i][1])*(pos[i][3]-pos[i][2]);
    }

    boolean in(int i,int y,int x){
        return y<=pos[i][0]&&y>=pos[i][1] && x<=pos[i][3] && x>= pos[i][2];
    }

    boolean ck(int i,int j){
        return !in(i, pos[j][0],pos[j][3]) &&
        !in(i, pos[j][0],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][3]);
    }

    void go(int c,int sum){
        if(sum>=r) return;
        if(c==n){
            for(int i=0;i<k;++i) {
                if (!gd(i)) return;
            }

            for(int i=0;i<k;++i){
                for(int j=i+1;j<k;++j){
                    if(!ck(i,j)){
                        return;
                    }
                }
            }
            r = sum;
            return;
        }

        for(int i=0;i<k;++i){
            int tmp[] = pos[i].clone();
            int zx = x[c];
            int zy = y[c];

            int prev = area(i);

            pos[i][0] = Math.max(pos[i][0],zy);
            pos[i][1] = Math.min(pos[i][1],zy);

            pos[i][2] = Math.min(pos[i][2],zx);
            pos[i][3] = Math.max(pos[i][3],zx);

            int cur = area(i);

            go(c+1,sum-prev+cur);

            pos[i] = tmp;
        }

    }

    int dx[] = {0,0,1,-1};
    int dy[] = {1,-1,0,0};
    boolean xiao(int mp[][]){
        boolean ok = false;
        boolean mk[][] = new boolean[7][5];
        for(int i=0;i<7;++i){
            for(int j=0;j<5;++j){
                if(mp[i][j]==0) continue;
                int k = j+1;
                int c = mp[i][j];
                while(k<5&&mp[i][k]==c) k++;
                if(k-j>=3){
                    ok = true;
                    for(int u=j;u<k;++u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<5;++i){
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) break;
                int k = j-1;
                int c = mp[i][j];
                while(k>=0&&mp[i][k]==c) k--;
                if(j-k>=3){
                    ok = true;
                    for(int u=j;u>k;--u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<7;++i) {
            for (int j = 0; j < 5; ++j) {
                if (mp[i][j] > 0 && mk[i][j]) {
                    mp[i][j] = 0;
                }
            }
        }
      return ok;
    }

    void luo(int[][] mp){
        for(int i=0;i<5;++i){
            int f = 6;
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) continue;
                mp[i][f] = mp[i][j];f--;
                mp[i][j] = 0;
            }
        }
    }

    void go(int mp[][]){

        while(xiao(mp)){
            luo(mp);
        }

    }

    void sort(int a[]){
        Arrays.sort(a);
    }

    int gcd(int a,int b){
        return b==0?a:gcd(b,a%b);
    }

    void solve() {
//        int n = ni();
//        int mp[][] = new int[7][5];
//        // less than 10;
//
//        for(int i=0;i<5;++i){
//            int x = 6;
//            while(true){
//                int num = ni();
//                if(num==0) break;
//                mp[x][i] = num;
//                x--;
//            }
//        }

            int n = ni();

            int cur = ni();
            println(cur);
            boolean vis[] = new boolean[n+1];
            vis[cur] = true;

//            List<Integer> ch[] = new ArrayList[n+1];
//
//            for(int i=1;i<=n;++i){
//                ch[i] = new ArrayList<>();
//            }
           // int cur = root;
        int ma = n;
        if(ma==cur){
            ma--;
        }
        for(int i=0;i<n-2;++i){
                int v = ni();
                if(!vis[v]){
                    println(cur+" "+v);
                    vis[v] = true;
                    cur = v;
                    if(v==ma){
                        ma--;
                    }
                }else{
                    while(vis[ma]) ma--;
                    println(cur+" "+ma);
                    vis[ma] = true;
                    ma--;
                    cur = v;
                }
            }
        while(vis[ma]) ma--;
        println(cur+" "+ma);

//            init(n+1);
//            for(int i=1;i<=n;++i){
//                for(int go:ch[i]){
//                    if(root(go)==root(i)){
//                        println(-1); return;
//                    }
//                    combine(go,i);
//                }
//            }

//                println(root);
//                for(int i=1;i<=n;++i){
//                    for(int go:ch[i]){
//                        println(go+" "+i);
//                    }
//                }
//

    }

    InputStream is;
    PrintWriter out;

    void run() throws Exception {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private char ncc() {
        int b = readByte();
        return (char) b;
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private String nline() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!isSpaceChar(b) || b == ' ') {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[][] nm(int n, int m) {
        char[][] a = new char[n][];
        for (int i = 0; i < n; i++) a[i] = ns(m);
        return a;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private long[] nal(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nl();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = num * 10 + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    void print(Object obj) {
        out.print(obj);
    }

    void println(Object obj) {
        out.println(obj);
    }

    void println() {
        out.println();
    }

    void printArray(int a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }

    void printArray(long a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

// written by luchy0120

public class Main {
    public static void main(String[] args) throws Exception {

        new Main().run();
    }

    static int groups = 0;
    static int[] fa;
    static int[] sz;

    static void init(int n) {
        groups = n;
        fa = new int[n];
        for (int i = 1; i < n; ++i) {
            fa[i] = i;
        }
        sz = new int[n];
        Arrays.fill(sz, 1);
    }

    static int root(int p) {
        while (p != fa[p]) {
            fa[p] = fa[fa[p]];
            p = fa[p];
        }
        return p;
    }

    static void combine(int p, int q) {
        int i = root(p);
        int j = root(q);
        if (i == j) {
            return;
        }
        if (sz[i] < sz[j]) {
            fa[i] = j;
            sz[j] += sz[i];
        } else {
            fa[j] = i;
            sz[i] += sz[j];
        }
        groups--;
    }

    int color[],dfn[],low[],stack[],cnt[];
    boolean vis[];
    boolean iscut[];
    int deep,top,n,m,sum,ans;
    List<Integer> g[];

    void tarjan(int u,int fa) {
        int child = 0;
        dfn[u]=++deep;
        low[u]=deep;
        vis[u]=true;
        stack[++top]=u;
        int sz=g[u].size();
        for(int i=0;i<sz;i++) {
            int v =g[u].get(i);
            if(v==fa) continue;
            if(dfn[v]==0) {
                child++;
                tarjan(v,u);
                low[u]=Math.min(low[u],low[v]);
            } else {
                if(vis[v]) {
                    low[u]=Math.min(low[u],low[v]);
                }
            }
        }
        if(fa<0&&child==1){
            iscut[u] =true;
        }

        if(dfn[u]==low[u]) {
            iscut[u] = true;
            color[u]=++sum;
            vis[u]=false;
            while(stack[top]!=u) {
                color[stack[top]]=sum;
                vis[stack[top--]]=false;
            }
            top--;
        }
    }

    int h[],to[],ne[];int ct =0;
    void add(int u,int v){
        u--;v--;
        to[ct] = v;
        ne[ct] = h[u];
        h[u] = ct++;
    }

    void graph(int n,int m){
        h = new int[n];
        Arrays.fill(h,-1);
        ne = new int[2*m];
        to = new int[2*m];
        ct = 0;
    }

    static long mul(long a, long b, long p)
    {
        long res=0,base=a;
        while(b>0)
        {
            if((b&1L)>0)
                res=(res+base)%p;
            base=(base+base)%p;
            b>>=1;
        }
        return res;
    }

    static long mod_pow(long k,long n,long p){
        long res = 1L;
        long temp = (k%p+p)%p;
        while(n!=0L){
            if((n&1L)==1L){
                res = ((res*temp)%p+p)%p;
            }
            temp = ((temp * temp)%p+p)%p;
            n = n>>1L;
        }
        return res%p;
    }
    public static String roundS(double result, int scale){
        String fmt = String.format("%%.%df", scale);
        return String.format(fmt, result);
    }

    int x[];
    int y[];
    int k ;
    int r = 1000000000;
    int[][] pos;

    boolean gd(int i){
        if(pos[i][0]<pos[i][1]) return false;
        if(pos[i][2]>pos[i][3]) return false;
        return true;
    }

    int area(int i){
        if(pos[i][0]<=pos[i][1]) return 0;
        if(pos[i][2]>=pos[i][3]) return 0;
        return (pos[i][0]-pos[i][1])*(pos[i][3]-pos[i][2]);
    }

    boolean in(int i,int y,int x){
        return y<=pos[i][0]&&y>=pos[i][1] && x<=pos[i][3] && x>= pos[i][2];
    }

    boolean ck(int i,int j){
        return !in(i, pos[j][0],pos[j][3]) &&
        !in(i, pos[j][0],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][2]) &&
        !in(i, pos[j][1],pos[j][3]);
    }

    void go(int c,int sum){
        if(sum>=r) return;
        if(c==n){
            for(int i=0;i<k;++i) {
                if (!gd(i)) return;
            }

            for(int i=0;i<k;++i){
                for(int j=i+1;j<k;++j){
                    if(!ck(i,j)){
                        return;
                    }
                }
            }
            r = sum;
            return;
        }

        for(int i=0;i<k;++i){
            int tmp[] = pos[i].clone();
            int zx = x[c];
            int zy = y[c];

            int prev = area(i);

            pos[i][0] = Math.max(pos[i][0],zy);
            pos[i][1] = Math.min(pos[i][1],zy);

            pos[i][2] = Math.min(pos[i][2],zx);
            pos[i][3] = Math.max(pos[i][3],zx);

            int cur = area(i);

            go(c+1,sum-prev+cur);

            pos[i] = tmp;
        }

    }

    int dx[] = {0,0,1,-1};
    int dy[] = {1,-1,0,0};
    boolean xiao(int mp[][]){
        boolean ok = false;
        boolean mk[][] = new boolean[7][5];
        for(int i=0;i<7;++i){
            for(int j=0;j<5;++j){
                if(mp[i][j]==0) continue;
                int k = j+1;
                int c = mp[i][j];
                while(k<5&&mp[i][k]==c) k++;
                if(k-j>=3){
                    ok = true;
                    for(int u=j;u<k;++u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<5;++i){
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) break;
                int k = j-1;
                int c = mp[i][j];
                while(k>=0&&mp[i][k]==c) k--;
                if(j-k>=3){
                    ok = true;
                    for(int u=j;u>k;--u){
                        mk[i][u] = true;
                    }
                }
            }
        }

        for(int i=0;i<7;++i) {
            for (int j = 0; j < 5; ++j) {
                if (mp[i][j] > 0 && mk[i][j]) {
                    mp[i][j] = 0;
                }
            }
        }
      return ok;
    }

    void luo(int[][] mp){
        for(int i=0;i<5;++i){
            int f = 6;
            for(int j=6;j>=0;--j){
                if(mp[i][j]==0) continue;
                mp[i][f] = mp[i][j];f--;
                mp[i][j] = 0;
            }
        }
    }

    void go(int mp[][]){

        while(xiao(mp)){
            luo(mp);
        }

    }

    void sort(int a[]){
        Arrays.sort(a);
    }

    int gcd(int a,int b){
        return b==0?a:gcd(b,a%b);
    }

    void solve() {
//        int n = ni();
//        int mp[][] = new int[7][5];
//        // less than 10;
//
//        for(int i=0;i<5;++i){
//            int x = 6;
//            while(true){
//                int num = ni();
//                if(num==0) break;
//                mp[x][i] = num;
//                x--;
//            }
//        }

            int n = ni();

            int root = ni();

            boolean vis[] = new boolean[n+1];
            vis[root] = true;

            List<Integer> ch[] = new ArrayList[n+1];

            for(int i=1;i<=n;++i){
                ch[i] = new ArrayList<>();
            }
            int cur = root;
        int ma = n;
        if(ma==root){
            ma--;
        }
        for(int i=0;i<n-2;++i){
                int v = ni();
                if(!vis[v]){
                    ch[cur].add(v);
                    vis[v] = true;
                    cur = v;
                    if(v==ma){
                        ma--;
                    }
                }else{
                    while(vis[ma]) ma--;
                    ch[cur].add(ma);
                    vis[ma] = true;
                    ma--;
                    cur = v;
                }
            }
        while(vis[ma]) ma--;
        ch[cur].add(ma);

//            init(n+1);
//            for(int i=1;i<=n;++i){
//                for(int go:ch[i]){
//                    if(root(go)==root(i)){
//                        println(-1); return;
//                    }
//                    combine(go,i);
//                }
//            }

                println(root);
                for(int i=1;i<=n;++i){
                    for(int go:ch[i]){
                        println(go+" "+i);
                    }
                }

    }

    InputStream is;
    PrintWriter out;

    void run() throws Exception {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private char ncc() {
        int b = readByte();
        return (char) b;
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private String nline() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!isSpaceChar(b) || b == ' ') {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[][] nm(int n, int m) {
        char[][] a = new char[n][];
        for (int i = 0; i < n; i++) a[i] = ns(m);
        return a;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private long[] nal(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nl();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {
        }
        ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') num = num * 10 + (b - '0');
            else return minus ? -num : num;
            b = readByte();
        }
    }

    void print(Object obj) {
        out.print(obj);
    }

    void println(Object obj) {
        out.println(obj);
    }

    void println() {
        out.println();
    }

    void printArray(int a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }

    void printArray(long a[],int from){
        int l = a.length;
        for(int i=from;i<l;++i){
            print(a[i]);
            if(i!=l-1){
                print(" ");
            }
        }
        println();
    }
}


/*
 * Created by cravuri on 12/28/19
 */

import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class DIYGarland {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n - 1];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt() - 1;
        }

        TreeSet<Integer> remaining = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            remaining.add(i);
        }

        int[] parent = new int[n];
        for (int i = 0; i < n; i++) {
            parent[i] = -1;
        }

        TreeMap<Integer, Integer> within = new TreeMap<>();

        int root = a[0];
        remaining.remove(root);
        within.put(remaining.last(), root);
        remaining.remove(remaining.last());
        for (int i = 1; i < a.length; i++) {
            if (within.containsKey(a[i])) {
                int p = within.get(a[i]);
                parent[a[i]] = p;
                within.remove(a[i]);
                within.put(remaining.last(), a[i]);
                remaining.remove(remaining.last());
            } else if (!remaining.contains(a[i])) {
                within.put(remaining.last(), a[i]);
                remaining.remove(remaining.last());
            } else {
                int smallest = within.firstKey();
                int p = within.get(smallest);
                parent[a[i]] = p;
                within.put(smallest, a[i]);
            }
        }
        for (Integer k : within.keySet()) {
            parent[k] = within.get(k);
        }

        int count = 0;
        for (int i = 0; i < parent.length; i++) {
            if (parent[i] == -1) {
                count++;
            }
        }
        if (count != 1) {
            System.out.println(-1);
            return;
        }

        System.out.println(root + 1);
        for (int i = 0; i < n; i++) {
            if (i != root) {
                System.out.println((i + 1) + " " + (parent[i] + 1));
            }
        }
    }

}


/*
 * Created by cravuri on 12/28/19
 */

import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class DIYGarland {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n - 1];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt() - 1;
        }

        TreeSet<Integer> remaining = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            remaining.add(i);
        }

        int[] parent = new int[n];
        for (int i = 0; i < n; i++) {
            parent[i] = -1;
        }

        TreeMap<Integer, Integer> within = new TreeMap<>();

        int root = a[0];
        remaining.remove(root);
        within.put(remaining.last(), root);
        remaining.remove(remaining.last());
        for (int i = 1; i < a.length; i++) {
            if (within.containsKey(a[i])) {
                int p = within.get(a[i]);
                parent[a[i]] = p;
                within.remove(a[i]);
                within.put(remaining.last(), a[i]);
                remaining.remove(remaining.last());
            } else if (!remaining.contains(a[i])) {
                within.put(remaining.last(), a[i]);
                remaining.remove(remaining.last());
            } else {
                int smallest = within.firstKey();
                int p = within.get(smallest);
                parent[a[i]] = p;
                within.put(smallest, a[i]);
                remaining.remove(a[i]);
            }
        }
        for (Integer k : within.keySet()) {
            parent[k] = within.get(k);
        }

        int count = 0;
        for (int i = 0; i < parent.length; i++) {
            if (parent[i] == -1) {
                count++;
            }
        }
        if (count != 1) {
            System.out.println(-1);
            return;
        }

        System.out.println(root + 1);
        for (int i = 0; i < n; i++) {
            if (i != root) {
                System.out.println((i + 1) + " " + (parent[i] + 1));
            }
        }
    }

}


// Don't place your source in a package
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
// Please name your class Main
public class Main {

	static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    static int read() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }
    static String readString() throws IOException {
        in.nextToken();
        return in.sval;
	}

	public static void main (String[] args) throws java.lang.Exception {
	    Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//InputReader in = new InputReader(System.in);

		int T=1;
		for(int t=0;t<T;t++){
			int n=in.nextInt();
			int A[]=new int[n-1];

			for(int i=0;i<n-1;i++){
				A[i]=in.nextInt();
			}
			Solution s=new Solution();
			s.solution(n,A);
			out.flush();
		}

	}

}

class Solution{
	//constant variable
	final int MAX=Integer.MAX_VALUE;
	final int MIN=Integer.MIN_VALUE;
	//Set<Integer>adjecent[];
	//////////////////////////////

	Map<Integer,Integer>map=new HashMap<>();

	public void solution(int n,int A[]){

		//where A[i] is the index of the main lamp for the i-th wire

		//We define the importance of the wire as the sum of brightness values
		//over all lamps that become disconnected from the grid if the wire is cut
		List<int[]>res=new ArrayList<>();
		int root=A[0];
		int in[]=new int[n+1];
		for(int i:A){
			in[i]++;
		}
		int max[]=new int[n+1];
		for(int i=0;i<max.length;i++){
			max[i]=i;
		}

		PriorityQueue<Integer>pq=new PriorityQueue<>((a,b)->{
			return max[a]-max[b];
		});
		int j=A.length-1;
		for(int i=1;i<=n;i++){
			if(in[i]==0){//leaf
				pq.add(i);
			}
		}

		while(j>=0){
			int cur=A[j];
			int leaf=pq.poll();
			res.add(new int[]{cur,leaf});
			max[cur]=Math.max(max[cur],max[leaf]);
			in[cur]--;
			if(in[cur]==0){
				pq.add(cur);
			}

			j--;
		}

		msg(root+"");
		for(int pair[]:res){
			msg(pair[0]+" "+pair[1]);
		}
	}

	public void put(int i){
		if(!map.containsKey(i))map.put(i,0);
		map.put(i,map.get(i)+1);
	}

	/*public void tarjan(int p,int r){
		if(cut)return;
		List<Integer>childs=adjecent[r];
		dis[r]=low[r]=time;
		time++;

		//core for tarjan
		int son=0;
		for(int c:childs){
			if(ban==c||c==p)continue;
			if(dis[c]==-1){
				son++;
				tarjan(r,c);
				low[r]=Math.min(low[r],low[c]);
				if((r==root&&son>1)||(low[c]>=dis[r]&&r!=root)){
					cut=true;
					return;
				}
			}else{
				if(c!=p){
					low[r]=Math.min(low[r],dis[c]);
				}
			}
		}

	}*/

	//helper function I would use
	public void remove(Map<Integer,Integer>map,int i){
		map.put(i,map.get(i)-1);
		if(map.get(i)==0)map.remove(i);
	}

	public int gcd(int num1, int num2) {
      if (num2 != 0){
         return gcd(num2, num1 % num2);
      } else{
         return num1;
      }
   }

	public void ascii(String s){
		for(char c:s.toCharArray()){
			System.out.print((c-'a')+" ");
		}
		msg("");
	}

	public int flip(int i){
		if(i==0)return 1;
		else return 0;
	}

	public boolean[] primes(int n){
		boolean A[]=new boolean[n+1];
		for(int i=2;i<=n;i++){
			if(A[i]==false){
				for(int j=i+i;j<=n;j+=i){
					A[j]=true;
				}
			}
		}
		return A;
	}

	public void msg(String s){
		System.out.println(s);
	}

	public void msg1(String s){
		System.out.print(s);
	}

	public int[] kmpPre(String p){
		int pre[]=new int[p.length()];
		int l=0,r=1;
		while(r<p.length()){
			if(p.charAt(l)==p.charAt(r)){
				pre[r]=l+1;
				l++;r++;
			}else{
				if(l==0)r++;
				else l=pre[l-1];
			}
		}
		return pre;
	}

	public boolean isP(String s){
		int l=0,r=s.length()-1;
		while(l<r){
			if(s.charAt(l)!=s.charAt(r))return false;
			l++;r--;
		}
		return true;
	}

	public int find(int nums[],int x){//union find => find method
		if(nums[x]==x)return x;
		int root=find(nums,nums[x]);
		nums[x]=root;
		return root;
	}

	public boolean check(int grid[][],int r,int c){
		if(r<0||c<0||r>=grid.length||c>=grid[0].length)return false;
		return true;
	}

	public int get(int A[],int i){
		if(i<0||i>=A.length)return 0;
		return A[i];
	}
	public int[] copy1(int A[]){
		int a[]=new int[A.length];
		for(int i=0;i<a.length;i++)a[i]=A[i];
		return a;
	}

	public int[] copy2(int A[]){
		int a[]=new int[A.length];
		for(int i=0;i<a.length;i++)a[i]=A[i];
		return a;
	}

	public void print1(int A[]){
		for(long i:A)System.out.print(i+" ");
		System.out.println();
	}
	public void print2(int A[][]){
		for(int i=0;i<A.length;i++){
			for(int j=0;j<A[0].length;j++){
				System.out.print(A[i][j]+" ");
			}System.out.println();
		}
	}

	public int min(int a,int b){
		return Math.min(a,b);
	}

	public int[][] matrixdp(int[][] grid) {
        if(grid.length==0)return new int[][]{};
        int res[][]=new int[grid.length][grid[0].length];
        for(int i=0;i<grid.length;i++){
            for(int j=0;j<grid[0].length;j++){
                res[i][j]=grid[i][j]+get(res,i-1,j)+get(res,i,j-1)-get(res,i-1,j-1);
            }
        }
        return res;
    }

    public int get(int grid[][],int i,int j){
        if(i<0||j<0||i>=grid.length||j>=grid[0].length)return 0;
        return grid[i][j];
    }

	public int[] suffixArray(String s){
		int n=s.length();
		Suffix A[]=new Suffix[n];

		for(int i=0;i<n;i++){
			A[i]=new Suffix(i,s.charAt(i)-'a',0);
		}

		for(int i=0;i<n;i++){
			if(i==n-1){
				A[i].next=-1;
			}else{
				A[i].next=A[i+1].rank;
			}
		}
		Arrays.sort(A);

		for(int len=4;len<A.length*2;len<<=1){
			int in[]=new int[A.length];
			int rank=0;
			int pre=A[0].rank;
			A[0].rank=rank;
			in[A[0].index]=0;
			for(int i=1;i<A.length;i++){//rank for the first two letter
				if(A[i].rank==pre&&A[i].next==A[i-1].next){
					pre=A[i].rank;
					A[i].rank=rank;
				}else{
					pre=A[i].rank;
					A[i].rank=++rank;
				}
				in[A[i].index]=i;
			}

			for(int i=0;i<A.length;i++){
				int next=A[i].index+len/2;
				if(next>=A.length){
					A[i].next=-1;
				}else{
					A[i].next=A[in[next]].rank;
				}
			}

			Arrays.sort(A);
		}

		int su[]=new int[A.length];
		for(int i=0;i<su.length;i++){
			su[i]=A[i].index;
		}
		return su;
	}

}

//suffix array Struct
class Suffix implements Comparable<Suffix>{
	int index;
	int rank;
	int next;
	public Suffix(int i,int rank,int next){
		this.index=i;
		this.rank=rank;
		this.next=next;
	}

	@Override
	public int compareTo(Suffix other) {
		if(this.rank==other.rank){
			return this.next-other.next;
		}
		return this.rank-other.rank;
	}

	public String toString(){
		return this.index+"   "+this.rank+"   "+this.next+"  ";
	}
}

class Wrapper implements Comparable<Wrapper>{
	int spf;int cnt;
	public Wrapper(int spf,int cnt){
		this.spf=spf;
		this.cnt=cnt;
	}

	@Override
	public int compareTo(Wrapper other) {
		return this.spf-other.spf;
	}
}

    class Node{//what the range would be for that particular node
		boolean state=false;
        int l=0,r=0;
		int ll=0,rr=0;
        public Node(boolean state){
            this.state=state;
        }
    }

	class Seg1{
			int A[];
			public Seg1(int A[]){
				this.A=A;
			}

			public void update(int left,int right,int val,int s,int e,int id){
				if(left<0||right<0||left>right)return;
				if(left==s&&right==e){

					A[id]+=val;
					return;
				}
				int mid=s+(e-s)/2; //[s,mid] [mid+1,e]

				if(left>=mid+1){
					update(left,right,val,mid+1,e,id*2+2);
				}else if(right<=mid){
					update(left,right,val,s,mid,id*2+1);
				}else{
					update(left,mid,val,s,mid,id*2+1);
					update(mid+1,right,val,mid+1,e,id*2+2);
				}
			}

			public int query(int i,int add,int s,int e,int id){

				if(s==e&&i==s){
					return A[id]+add;
				}

				int mid=s+(e-s)/2; //[s,mid] [mid+1,e]

				if(i>=mid+1){
					return query(i,A[id]+add,mid+1,e,id*2+2);
				}else{
					return query(i,A[id]+add,s,mid,id*2+1);
				}
			}
	}


// Don't place your source in a package
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
// Please name your class Main
public class Main {

	static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    static int read() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }
    static String readString() throws IOException {
        in.nextToken();
        return in.sval;
	}

	public static void main (String[] args) throws java.lang.Exception {
	    Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//InputReader in = new InputReader(System.in);

		int T=1;
		for(int t=0;t<T;t++){
			int n=in.nextInt();
			int A[]=new int[n-1];

			for(int i=0;i<n-1;i++){
				A[i]=in.nextInt();
			}
			Solution s=new Solution();
			s.solution(n,A);
			out.flush();
		}

	}

}

class Solution{
	//constant variable
	final int MAX=Integer.MAX_VALUE;
	final int MIN=Integer.MIN_VALUE;
	//Set<Integer>adjecent[];
	//////////////////////////////

	Map<Integer,Integer>map=new HashMap<>();

	public void solution(int n,int A[]){

		//where A[i] is the index of the main lamp for the i-th wire

		//We define the importance of the wire as the sum of brightness values
		//over all lamps that become disconnected from the grid if the wire is cut
		int root=A[0];
		Set<Integer>set=new HashSet<>();
		List<Integer>leafs=new ArrayList<>();
		List<int[]>res=new ArrayList<>();
		for(int i:A){
			set.add(i);
		}

		for(int i=1;i<=n;i++){
			if(!set.contains(i)){
				leafs.add(i);
			}
		}

		set=new HashSet<>();
		set.add(root);
		int index=A.length-1;
		PriorityQueue<int[]>pq=new PriorityQueue<>((a,b)->{
			return a[1]-b[1];
		});

		for(int i=0;i<leafs.size();i++){
			int leaf=leafs.get(i);
			res.add(new int[]{A[index],leaf});
			pq.add(new int[]{A[index],Math.max(leaf,A[index])});
			index--;
		}

		while(index>=0){
			int top[]=pq.poll();
			int main=A[index];
			res.add(new int[]{main,top[0]});
			set.add(top[0]);
			if(!set.contains(main))pq.add(new int[]{main,Math.max(main,top[1])});
			//System.out.println(main+"   "+top[0]+"  "+top[1]);
			index--;
		}

		msg(root+"");
		for(int pair[]:res){
			msg(pair[0]+" "+pair[1]);
		}
	}

	public void put(int i){
		if(!map.containsKey(i))map.put(i,0);
		map.put(i,map.get(i)+1);
	}

	/*public void tarjan(int p,int r){
		if(cut)return;
		List<Integer>childs=adjecent[r];
		dis[r]=low[r]=time;
		time++;

		//core for tarjan
		int son=0;
		for(int c:childs){
			if(ban==c||c==p)continue;
			if(dis[c]==-1){
				son++;
				tarjan(r,c);
				low[r]=Math.min(low[r],low[c]);
				if((r==root&&son>1)||(low[c]>=dis[r]&&r!=root)){
					cut=true;
					return;
				}
			}else{
				if(c!=p){
					low[r]=Math.min(low[r],dis[c]);
				}
			}
		}

	}*/

	//helper function I would use
	public void remove(Map<Integer,Integer>map,int i){
		map.put(i,map.get(i)-1);
		if(map.get(i)==0)map.remove(i);
	}

	public int gcd(int num1, int num2) {
      if (num2 != 0){
         return gcd(num2, num1 % num2);
      } else{
         return num1;
      }
   }

	public void ascii(String s){
		for(char c:s.toCharArray()){
			System.out.print((c-'a')+" ");
		}
		msg("");
	}

	public int flip(int i){
		if(i==0)return 1;
		else return 0;
	}

	public boolean[] primes(int n){
		boolean A[]=new boolean[n+1];
		for(int i=2;i<=n;i++){
			if(A[i]==false){
				for(int j=i+i;j<=n;j+=i){
					A[j]=true;
				}
			}
		}
		return A;
	}

	public void msg(String s){
		System.out.println(s);
	}

	public void msg1(String s){
		System.out.print(s);
	}

	public int[] kmpPre(String p){
		int pre[]=new int[p.length()];
		int l=0,r=1;
		while(r<p.length()){
			if(p.charAt(l)==p.charAt(r)){
				pre[r]=l+1;
				l++;r++;
			}else{
				if(l==0)r++;
				else l=pre[l-1];
			}
		}
		return pre;
	}

	public boolean isP(String s){
		int l=0,r=s.length()-1;
		while(l<r){
			if(s.charAt(l)!=s.charAt(r))return false;
			l++;r--;
		}
		return true;
	}

	public int find(int nums[],int x){//union find => find method
		if(nums[x]==x)return x;
		int root=find(nums,nums[x]);
		nums[x]=root;
		return root;
	}

	public boolean check(int grid[][],int r,int c){
		if(r<0||c<0||r>=grid.length||c>=grid[0].length)return false;
		return true;
	}

	public int get(int A[],int i){
		if(i<0||i>=A.length)return 0;
		return A[i];
	}
	public int[] copy1(int A[]){
		int a[]=new int[A.length];
		for(int i=0;i<a.length;i++)a[i]=A[i];
		return a;
	}

	public int[] copy2(int A[]){
		int a[]=new int[A.length];
		for(int i=0;i<a.length;i++)a[i]=A[i];
		return a;
	}

	public void print1(int A[]){
		for(long i:A)System.out.print(i+" ");
		System.out.println();
	}
	public void print2(int A[][]){
		for(int i=0;i<A.length;i++){
			for(int j=0;j<A[0].length;j++){
				System.out.print(A[i][j]+" ");
			}System.out.println();
		}
	}

	public int min(int a,int b){
		return Math.min(a,b);
	}

	public int[][] matrixdp(int[][] grid) {
        if(grid.length==0)return new int[][]{};
        int res[][]=new int[grid.length][grid[0].length];
        for(int i=0;i<grid.length;i++){
            for(int j=0;j<grid[0].length;j++){
                res[i][j]=grid[i][j]+get(res,i-1,j)+get(res,i,j-1)-get(res,i-1,j-1);
            }
        }
        return res;
    }

    public int get(int grid[][],int i,int j){
        if(i<0||j<0||i>=grid.length||j>=grid[0].length)return 0;
        return grid[i][j];
    }

	public int[] suffixArray(String s){
		int n=s.length();
		Suffix A[]=new Suffix[n];

		for(int i=0;i<n;i++){
			A[i]=new Suffix(i,s.charAt(i)-'a',0);
		}

		for(int i=0;i<n;i++){
			if(i==n-1){
				A[i].next=-1;
			}else{
				A[i].next=A[i+1].rank;
			}
		}
		Arrays.sort(A);

		for(int len=4;len<A.length*2;len<<=1){
			int in[]=new int[A.length];
			int rank=0;
			int pre=A[0].rank;
			A[0].rank=rank;
			in[A[0].index]=0;
			for(int i=1;i<A.length;i++){//rank for the first two letter
				if(A[i].rank==pre&&A[i].next==A[i-1].next){
					pre=A[i].rank;
					A[i].rank=rank;
				}else{
					pre=A[i].rank;
					A[i].rank=++rank;
				}
				in[A[i].index]=i;
			}

			for(int i=0;i<A.length;i++){
				int next=A[i].index+len/2;
				if(next>=A.length){
					A[i].next=-1;
				}else{
					A[i].next=A[in[next]].rank;
				}
			}

			Arrays.sort(A);
		}

		int su[]=new int[A.length];
		for(int i=0;i<su.length;i++){
			su[i]=A[i].index;
		}
		return su;
	}

}

//suffix array Struct
class Suffix implements Comparable<Suffix>{
	int index;
	int rank;
	int next;
	public Suffix(int i,int rank,int next){
		this.index=i;
		this.rank=rank;
		this.next=next;
	}

	@Override
	public int compareTo(Suffix other) {
		if(this.rank==other.rank){
			return this.next-other.next;
		}
		return this.rank-other.rank;
	}

	public String toString(){
		return this.index+"   "+this.rank+"   "+this.next+"  ";
	}
}

class Wrapper implements Comparable<Wrapper>{
	int spf;int cnt;
	public Wrapper(int spf,int cnt){
		this.spf=spf;
		this.cnt=cnt;
	}

	@Override
	public int compareTo(Wrapper other) {
		return this.spf-other.spf;
	}
}

    class Node{//what the range would be for that particular node
		boolean state=false;
        int l=0,r=0;
		int ll=0,rr=0;
        public Node(boolean state){
            this.state=state;
        }
    }

	class Seg1{
			int A[];
			public Seg1(int A[]){
				this.A=A;
			}

			public void update(int left,int right,int val,int s,int e,int id){
				if(left<0||right<0||left>right)return;
				if(left==s&&right==e){

					A[id]+=val;
					return;
				}
				int mid=s+(e-s)/2; //[s,mid] [mid+1,e]

				if(left>=mid+1){
					update(left,right,val,mid+1,e,id*2+2);
				}else if(right<=mid){
					update(left,right,val,s,mid,id*2+1);
				}else{
					update(left,mid,val,s,mid,id*2+1);
					update(mid+1,right,val,mid+1,e,id*2+2);
				}
			}

			public int query(int i,int add,int s,int e,int id){

				if(s==e&&i==s){
					return A[id]+add;
				}

				int mid=s+(e-s)/2; //[s,mid] [mid+1,e]

				if(i>=mid+1){
					return query(i,A[id]+add,mid+1,e,id*2+2);
				}else{
					return query(i,A[id]+add,s,mid,id*2+1);
				}
			}
	}


import java.util.*;
import java.io.*;
import java.awt.*;

public class DIYGarland {
    public static void main(String[] args) throws IOException
    {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(f.readLine());
        int[] a = new int[n-1];
        PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
        int[] b = new int[n+1];
        StringTokenizer st = new StringTokenizer(f.readLine());
        for (int i=0; i<n-1; i++)
        {
            a[i] = Integer.parseInt(st.nextToken());
        }
        Arrays.fill(b, -1);
        for (int i=n-2; i>=0; i--)
        {
            b[a[i]] = i;
        }
        Point[] p = new Point[n-1];
        for (int i=1; i<=n; i++)
        {
            if (b[i]==-1)
            {
                pq.add(i);
            }
        }

        int index = n-2;
        while(!pq.isEmpty()&& index>=0)
        {
            int x = pq.remove();
            p[index] = new Point(x, a[index]);
            if (b[a[index]]==index)
            {
                pq.add(a[index]);
            }
            index--;
        }
        int asdf = 0;
        if (index>0)
        {
            System.out.println(-1);
        }
        else
        {
            System.out.println(pq.remove());
            for (int i=0; i<n-1; i++)
            {
                System.out.println(p[i].x+ " " + p[i].y);
            }
        }
    }
}


import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
public class DIYGarland2 {
    public static void main(String[] args) throws IOException {
        Scan in = new Scan();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] arr = new int[n];
        int[] freq = new int[n + 1];
        for (int i = 0; i < n - 1; i++) {
            arr[i] = in.nextInt();
            freq[arr[i]]++;
        }
        out.println(arr[0]);
        PriorityQueue<Integer> q = new PriorityQueue<>();
        for (int i = 1; i <= n; i++) {
            if(freq[i] == 0){
                q.add(i);
            }
        }
        for (int i = n - 2; i >= 0; i--) {
            int x = q.poll();
            out.println(arr[i] + " " + x);
            freq[arr[i]]--;
            if(freq[arr[i]] == 0){
                q.add(arr[i]);
            }
        }
        out.close();
    }
    static class Scan {

        public java.io.InputStream stream = System.in;
        private final static byte EOF = -1, NL = '\n', D = '-', SPC = ' ', buffer[] = new byte[0xFFFF];
        private char cBuff[] = new char[0xFF];
        public int $index, $readCount, itr;

        private void inc() {
            cBuff = java.util.Arrays.copyOf(cBuff, cBuff.length << 1);
        }

        private boolean readLINE() throws IOException {
            if ($readCount == EOF) {
                return false;
            }
            for (itr = 0;;) {
                while ($index < $readCount) {
                    if (buffer[$index] != NL) {
                        if (itr == cBuff.length) {
                            inc();
                        }
                        cBuff[itr++] = (char) buffer[$index++];
                    } else {
                        $index++;
                        return true;
                    }
                }
                $index = 0;
                $readCount = stream.read(buffer);
                if ($readCount == EOF) {
                    return true;
                }
            }
        }

        private boolean readPRT() throws IOException {
            if ($readCount == EOF) {
                return false;
            }
            T:
            for (;;) {
                while ($index < $readCount) {
                    if (buffer[$index] > SPC) {
                        break T;
                    } else {
                        $index++;
                    }
                }
                $index = 0;
                $readCount = stream.read(buffer);
                if ($readCount == EOF) {
                    return false;
                }
            }
            for (itr = 0;;) {
                while ($index < $readCount) {
                    if (buffer[$index] > SPC) {
                        if (itr == cBuff.length) {
                            inc();
                        }
                        cBuff[itr++] = (char) buffer[$index++];
                    } else {
                        return true;
                    }
                }
                $index = 0;
                $readCount = stream.read(buffer);
                if ($readCount == EOF) {
                    return true;
                }
            }
        }

        public int nextInt() throws IOException {
            if (!readPRT()) {
                throw new IOException();
            } else {
                int v = 0, i = 0;
                boolean neg;
                if (cBuff[i] == D) {
                    neg = true;
                    i++;
                } else {
                    neg = false;
                }
                while (i < itr) {
                    v = (v << 3) + (v << 1) + cBuff[i++] - '0';
                }
                return neg ? -v : v;
            }
        }

        public long nextLong() throws IOException {
            if (!readPRT()) {
                throw new IOException();
            } else {
                long v = 0;
                int i = 0;
                boolean neg;
                if (cBuff[i] == D) {
                    neg = true;
                    i++;
                } else {
                    neg = false;
                }
                while (i < itr) {
                    v = (v << 3L) + (v << 1L) + cBuff[i++] - '0';
                }
                return neg ? -v : v;
            }
        }

        public char[] buffer() throws IOException {
            return readPRT() ? cBuff : null;
        }

        public String next() throws IOException {
            return readPRT() ? new String(cBuff, 0, itr) : null;
        }

        public char[] nextArr() throws IOException {
            return readPRT() ? java.util.Arrays.copyOf(cBuff, itr) : null;
        }

        public String nextLine() throws IOException {
            return readLINE() ? new String(cBuff, 0, itr) : null;
        }

        public char[] nextLineArr() throws IOException {
            return readLINE() ? java.util.Arrays.copyOf(cBuff, itr) : null;
        }

        public float nextFloat() throws IOException {
            return Float.parseFloat(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class F {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int n=fs.nextInt();
		Node[] nodes=new Node[n];
		for (int i=0; i<n; i++) {
			nodes[i]=new Node(i, i);
		}
		int[] parOrder=new int[n-1];
		for (int i=0; i+1<n; i++) {
			int next=fs.nextInt()-1;
			nodes[next].timesUsed++;
			parOrder[i]=next;
		}
		PriorityQueue<Node> leaves=new PriorityQueue<>();
		for (Node nn:nodes)
			if (nn.timesUsed==0) leaves.add(nn);
		ArrayList<Integer> firstEdges=new ArrayList<>(), secondEdges=new ArrayList<>();
		for (int ind=n-2; ind>=0; ind--) {
			Node nextLeaf=leaves.remove();
			Node nextPar=nodes[parOrder[ind]];
			nextPar.maxSubtreeVal=Math.max(nextPar.maxSubtreeVal, nextLeaf.maxSubtreeVal);
			nextPar.children.add(nextLeaf);
			nextPar.timesUsed--;
			if (nextPar.timesUsed==0) leaves.add(nextPar);
			firstEdges.add(nextPar.index+1);
			secondEdges.add(nextLeaf.index+1);
		}
		PrintWriter out=new PrintWriter(System.out);
		for (int i=0; i<firstEdges.size(); i++)
			out.println(firstEdges.get(i)+" "+secondEdges.get(i));
		out.close();
	}

	static class Node implements Comparable<Node> {
		int maxSubtreeVal, index;
		int timesUsed=0;
		ArrayList<Node> children=new ArrayList<>();

		public Node(int maxSubtreeVal, int index) {
			this.index=index;
			this.maxSubtreeVal=maxSubtreeVal;
		}

		public int compareTo(Node o) {
			return Integer.compare(maxSubtreeVal, o.maxSubtreeVal);
		}
	}

	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");

		public String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();

		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++)
				a[i]=nextInt();
			return a;
		}

		public long[] readLongArray(int n) {
			long[] a=new long[n];
			for (int i=0; i<n; i++)
				a[i]=nextLong();
			return a;
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class F {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int n=fs.nextInt();
		Node[] nodes=new Node[n];
		for (int i=0; i<n; i++) {
			nodes[i]=new Node(i, i);
		}
		int[] parOrder=new int[n-1];
		for (int i=0; i+1<n; i++) {
			int next=fs.nextInt()-1;
			nodes[next].timesUsed++;
			parOrder[i]=next;
		}
		PriorityQueue<Node> leaves=new PriorityQueue<>();
		for (Node nn:nodes)
			if (nn.timesUsed==0) leaves.add(nn);
		ArrayList<Integer> firstEdges=new ArrayList<>(), secondEdges=new ArrayList<>();
		for (int ind=n-2; ind>=0; ind--) {
			Node nextLeaf=leaves.remove();
			Node nextPar=nodes[parOrder[ind]];
			nextPar.maxSubtreeVal=Math.max(nextPar.maxSubtreeVal, nextLeaf.maxSubtreeVal);
			nextPar.children.add(nextLeaf);
			nextPar.timesUsed--;
			if (nextPar.timesUsed==0) leaves.add(nextPar);
			firstEdges.add(nextPar.index+1);
			secondEdges.add(nextLeaf.index+1);
		}
		PrintWriter out=new PrintWriter(System.out);
		out.println(leaves.peek().index+1);
		for (int i=0; i<firstEdges.size(); i++)
			out.println(firstEdges.get(i)+" "+secondEdges.get(i));
		out.close();
	}

	static class Node implements Comparable<Node> {
		int maxSubtreeVal, index;
		int timesUsed=0;
		ArrayList<Node> children=new ArrayList<>();

		public Node(int maxSubtreeVal, int index) {
			this.index=index;
			this.maxSubtreeVal=maxSubtreeVal;
		}

		public int compareTo(Node o) {
			return Integer.compare(maxSubtreeVal, o.maxSubtreeVal);
		}
	}

	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");

		public String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();

		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++)
				a[i]=nextInt();
			return a;
		}

		public long[] readLongArray(int n) {
			long[] a=new long[n];
			for (int i=0; i<n; i++)
				a[i]=nextLong();
			return a;
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.*;

public class Main {
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()){
				try{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine()  {
			String str = "";
			try{
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) throws IOException{
		FastReader in=new FastReader();
		BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
                int n = in.nextInt();

                int [] a = new int[n];
                for(int i = 1; i<n; i++){
                    a[i] = in.nextInt();
                }
                log.write(a[1] + "\n");

                boolean [] c = new boolean [n+1];

                int maxPow = n;

                for(int i = 1; i<n;i++){
                    c[a[i]] = true;
                    while(maxPow > 0 && c[maxPow] )
                        maxPow --;
                    if(i == n-1 || c[a[i+1]]){
                        log.write(a[i] + " " + maxPow + "\n");
                        c[maxPow] = true;
                    }else{
                        log.write(a[i+1]+" "+a[i] + "\n");
                    }
                }

		log.flush();
		log.close();

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.*;

public class Main {
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()){
				try{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine()  {
			String str = "";
			try{
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) throws IOException{
		FastReader in=new FastReader();
		BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
                int n = in.nextInt();

                int [] a = new int[n];
                for(int i = 1; i<n; i++){
                    a[i] = in.nextInt();
                }
                log.write(a[1] + "\n");

                boolean [] c = new boolean [n+1];

                int maxPow = n;

                for(int i = 1; i<n;i++){
                    c[a[i]] = true;
                    while(maxPow > 0 && c[maxPow] )
                        maxPow --;
                    if(i == n-1 || c[a[i+1]]){
                        log.write(a[i] + " " + maxPow + "\n");
                        c[maxPow] = true;
                    }else{
                        log.write(a[i+1]+" "+a[i] + "\n");
                    }

//                    System.out.println(c[a[i+1]]);
/*                    if(i < n-1 && !c[a[i+1]]){
                        log.write(a[i] + " " + a[i+1]+"\n");
                        c[a[i+1]] = true;
                    }else{
                        log.write(a[i] + " " + maxPow+"\n");
                        c[maxPow] = true;
                    }
*/

                }

		log.flush();
		log.close();

	}

    public static double round(double value, int places) {
        if (places < 0) throw new IllegalArgumentException();

        long factor = (long) Math.pow(10, places);
        value = value * factor;
        long tmp = Math.round(value);
        return (double) tmp / factor;
    }
}

class point implements Comparator<edge>{
    int i,x,y;

    @Override
    public int compare(edge t, edge t1) {
        return Double.compare(t1.d, t.d);
    }
}

class edge{
    int a,b;
    double d;

}

class vertex{
    vertex parent;
    int i;
    ArrayList<vertex> adj = new ArrayList<>();
    public void addUndirected(vertex v){
        this.adj.add(v);
        v.adj.add(this);
    }
    public void addDirected(vertex v){
        this.adj.add(v);
    }
}


import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[] a = sc.nextIntArray(n-1);
        for(int i = 0; i < n-1; i++){
            a[i]--;
        }
    	int root = a[0];
    	int last = -1;
    	boolean[] used = new boolean[n];
    	pw.println(root+1);
    	int cur = n - 1;
    	for (int i = 0; i < n - 1; i++){
    		used[a[i]] = true;
    		while (used[cur]){
    		    cur--;
    		}
    		if (i == n-2 || used[a[i+1]]){
    		    pw.println((a[i]+1)+" "+(cur+1));
    		    used[cur] = true;
    		}else{
    		    pw.println((a[i+1]+1)+" "+(a[i]+1));
    		}
    	}
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }

        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }

    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}


import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    private int INF = (int) 1e9;

    public static void main(String args[]) {
        Main main = new Main();
        try {
            main.solution();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    private void solution() throws FileNotFoundException {
//        Scanner in = new Scanner(new File("input.txt"));
        Scanner in = new Scanner(System.in);

        int n = in.nextInt(); // vertices
        int[] f = new int[n];
        int[] e = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {   // edges
            int v = in.nextInt();
            f[v - 1]++;
            e[i] = v - 1;
        }

//        for (int i = 0; i < n - 1; i++) {
//            System.out.println(e[i]);
//        }

        PriorityQueue<int[]> pq = new PriorityQueue<>((a1, b1) -> a1[1] - b1[1]);
        for (int i = 0; i < n; i++) {
            if (f[i] == 0) {
                pq.add(new int[] {i, i + 1});
            }
        }

        List<int[]> res = new ArrayList<>();
        boolean flag = true;
        for (int i = n - 2; i >= 0; i--) {
            int v = e[i];

            if (!pq.isEmpty()) {
                int[] l = pq.poll();
                int u = l[0];

                if (--f[v] == 0) {
                    pq.add(new int[]{v, Math.max(l[1], v + 1)});
                }
//                System.out.println(String.format("%d -> %d", v + 1, u + 1));
                res.add(new int[]{v + 1, u + 1});
            } else {
                flag = false;
                break;
            }
        }

        if (flag) {
            System.out.println(e[0] + 1);
            for (int[] edge: res) {
                System.out.println(edge[0] + " " + edge[1]);
            }
        } else {
            System.out.println(-1);
        }
    }

}

/*

 */


import java.util.*;

import java.util.*;

public class MainF {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int m = n - 1;
        int[] p = new int[n];
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < m; i++) {
            p[i] = in.nextInt();
            set.add(p[i]);
        }

        PriorityQueue<int[]> q = new PriorityQueue<>((a,b) -> a[1] - b[1]);
        for (int i = 1; i <= n; i++) {
            if (!set.contains(i)) {
                q.add(new int[]{i, (int)Math.pow(2, i)});
            }
        }

        List<int[]> edges = new ArrayList<>();
        int root = p[0];
        int count = 0;
        for (int i = m - 1; i >= 0; i--) {
            int[] a = q.poll();
            if (a == null) break;
            count++;
            edges.add(new int[]{p[i], a[0]});
            if (p[i] != root)
            q.add(new int[] {p[i], a[1] + p[i] * p[i]});
        }

        if (count < m) System.out.println(-1);
        else {
            System.out.println(root);
            for (int[] a: edges) {
                System.out.println(String.format("%d %d", a[0], a[1]));
            }
        }
    }

}


import java.io.*;
import java.util.*;

import javax.swing.plaf.synth.SynthSpinnerUI;

public class tr1 {
	static PrintWriter out;
	static StringBuilder sb;
	static int inf = (int) 1e9;
	static long mod = (long) 1e9 + 7;
	static int[] si;
	static ArrayList<Integer> primes;
	static HashSet<Integer> pr;
	static int n, k, m;
	static int[] in;
	static HashMap<Integer, Integer> factors;
	static HashSet<Integer> f;
	static int[] fac, a, b;
	static int[] l, r;
	static int[][] memo;
	static int[] numc;
	static TreeSet<Integer>[] ad;
	static HashMap<Integer, Integer> hm;
	static pair[] ed;
	static TreeSet<Integer>[] np;
	static TreeMap<pair, Integer> tm;
	static int[] le, re;
	static char[] h;
	static pair[] mm;
	static boolean[] vis;
	static int y;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int n = sc.nextInt();
		TreeSet<Integer> ts = new TreeSet<>();
		int[] a = new int[n - 1];
		for (int i = 0; i < n - 1; i++) {
			a[i] = sc.nextInt();
			ts.add(i + 1);
			ts.add(i + 2);
		}
		ad = new TreeSet[n + 1];
		int[] an = new int[n + 1];
		for (int i = 0; i <= n; i++)
			ad[i] = new TreeSet<>();
		TreeSet<Integer> took = new TreeSet<>();

		int maxn = ts.last();
		for (int i = 0; i < n - 1; i++) {
			if (a[i] == maxn) {
				ts.pollLast();
				ad[a[i]].add(ts.last());
				maxn = ts.last();
			} else if (took.contains(a[i])) {
				ts.pollLast();
				ad[a[i]].add(ts.last());
				maxn = ts.last();
			} else {
				ad[a[i]].add(ts.last());
			}
			if (ts.contains(a[i]))
				ts.remove(a[i]);
			took.add(a[i]);
			took.add(maxn);
		}
		//System.out.println(Arrays.toString(ad));
		PriorityQueue<pair>[] pq = new PriorityQueue[n + 1];
		for (int i = 0; i <= n; i++)
			pq[i] = new PriorityQueue<>();
		ArrayList<Integer>[] adj = new ArrayList[n + 1];
		for (int i = 0; i <= n; i++)
			adj[i] = new ArrayList<>();
		for (int i = 0; i < n - 1; i++) {
			pq[ad[a[i]].pollLast()].add(new pair(i, a[i]));
		}
	//	System.out.println(Arrays.toString(pq));
		for (int i = 0; i <= n; i++) {
			if (pq[i].size() == 0)
				continue;
			while (pq[i].size() > 1) {
				pair cur =pq[i].poll();
				adj[pq[i].peek().y].add(cur.y);
			}
			adj[pq[i].poll().y].add(i);
		}
		out.println(a[0]);
		for(int i=0;i<=n;i++)
			for(int v:adj[i])
				out.println(i+" "+v);
		out.flush();
	}

	static class pair implements Comparable<pair> {
		int x;
		int y;

		pair(int f, int t) {
			x = f;
			y = t;
			// z=u;
			// num = n;
		}

		public String toString() {
			return x + " " + y;
		}

		@Override
		public int compareTo(pair o) {
			if (x == o.x)
				return y - o.y;
			return x - o.x;
		}
	}

	static class pair1 implements Comparable<pair1> {
		int x;
		int y;
		int z;

		pair1(int f, int t, int u) {
			x = f;
			y = t;
			z = u;
			// num = n;
		}

		public String toString() {
			return x + " " + y;
		}

		@Override
		public int compareTo(pair1 o) {
			if (x == o.x)
				return y - o.y;
			return x - o.x;
		}
	}

	static public class FenwickTree { // one-based DS

		int n;
		int[] ft;

		FenwickTree(int size) {
			n = size;
			ft = new int[n + 1];
			// for(int i=1;i<=n;i++)
			// ft[i]=i;
		}

		int rsq(int b) // O(log n)
		{
			int sum = 0;
			while (b > 0) {
				sum += ft[b];
				b -= b & -b;
			} // min?
			return sum;
		}

		int rsq(int a, int b) {
			return rsq(b) - rsq(a - 1);
		}

		void point_update(int k, int val) // O(log n), update = increment
		{
			while (k <= n) {
				// System.out.println(k+" "+val);
				ft[k] += val;
				k += k & -k;
			} // min?
		}

		int point_query(int idx) // c * O(log n), c < 1
		{
			int sum = ft[idx];
			if (idx > 0) {
				int z = idx ^ (idx & -idx);
				--idx;
				while (idx != z) {
					// System.out.println("oo");
					sum -= ft[idx];
					idx ^= idx & -idx;
				}
			}
			return sum;
		}

		void scale(int c) {
			for (int i = 1; i <= n; ++i)
				ft[i] *= c;
		}

		int findIndex(int cumFreq) {
			int msk = n;
			while ((msk & (msk - 1)) != 0)
				msk ^= msk & -msk; // msk will contain the MSB of n

			int idx = 0;
			while (msk != 0) {
				int tIdx = idx + msk;
				if (tIdx <= n && cumFreq >= ft[tIdx]) {
					idx = tIdx;
					cumFreq -= ft[tIdx];
				}
				msk >>= 1;
			}
			if (cumFreq != 0)
				return -1;
			return idx;
		}
	}

	static public class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		long[] array, sTree, lazy;

		SegmentTree(long[] in) {
			array = in;
			N = in.length - 1;
			sTree = new long[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new long[N << 1];
			build(1, 1, N);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] += val;
			while (index > 1) {
				index >>= 1;
				sTree[index] = sTree[index << 1] + sTree[index << 1 | 1];
			}
		}

		void update_range(int i, int j, long val) // O(log n)
		{
			update_range(1, 1, N, i, j, val);
		}

		void update_range(int node, int b, int e, int i, int j, long val) {
			if (i > e || j < b)
				return;
			if (b >= i && e <= j) {
				sTree[node] += (e - b + 1) * val;
				lazy[node] += val;
			} else {
				int mid = b + e >> 1;
				propagate(node, b, mid, e);
				update_range(node << 1, b, mid, i, j, val);
				update_range(node << 1 | 1, mid + 1, e, i, j, val);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}

		}

		void propagate(int node, int b, int mid, int e) {
			lazy[node << 1] += lazy[node];
			lazy[node << 1 | 1] += lazy[node];
			sTree[node << 1] += (mid - b + 1) * lazy[node];
			sTree[node << 1 | 1] += (e - mid) * lazy[node];
			lazy[node] = 0;
		}

		long query(int i, int j) {
			return query(1, 1, N, i, j);
		}

		long query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return sTree[node];
			int mid = b + e >> 1;
			propagate(node, b, mid, e);
			long q1 = query(node << 1, b, mid, i, j);
			long q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return q1 + q2;

		}

	}

	static long gcd(long a, long b) {

		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	public int[] merge(int[] d, int st, int e) {
		if (st > e)
			return null;
		if (e == st) {
			int[] ans = { d[e] };
			return ans;
		}
		int mid = (st + e) / 2;
		int[] ans = new int[e - st + 1];
		int[] ll = merge(d, st, mid);
		int[] rr = merge(d, mid + 1, e);
		if (ll == null)
			return rr;
		if (rr == null)
			return ll;
		int iver = 0;
		int idxl = 0;
		int idxr = 0;
		for (int i = st; i <= e; i++) {
			if (ll[idxl] < rr[idxr]) {

			}
		}
		return ans;
	}

	public static class pair2 implements Comparable<pair2> {
		int a;
		int idx;

		pair2(int a, int i) {
			this.a = a;
			idx = i;
		}

		public String toString() {
			return a + " " + idx;
		}

		@Override
		public int compareTo(pair2 o) {
			// TODO Auto-generated method stub
			return idx - o.idx;
		}
	}

	static long inver(long x) {
		int a = (int) x;
		long e = (mod - 2);
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1) {
				// System.out.println(res*a);
				res = (int) ((1l * res * a) % mod);
			}
			a = (int) ((1l * a * a) % mod);
			e >>= 1;
		}
		// out.println(res+" "+x);
		return res % mod;
	}

	static int atMostSum(int arr[], int n, int k) {
		int sum = 0;
		int cnt = 0, maxcnt = 0;

		for (int i = 0; i < n; i++) {

			// If adding current element doesn't
			// cross limit add it to current window
			if ((sum + arr[i]) <= k) {
				sum += arr[i];
				cnt++;
			}

			// Else, remove first element of current
			// window and add the current element
			else if (sum != 0) {
				sum = sum - arr[i - cnt] + arr[i];
			}

			// keep track of max length.
			maxcnt = Math.max(cnt, maxcnt);
		}
		return maxcnt;
	}

	public static int[] longestSubarray(int[] inp) {
		// array containing prefix sums up to a certain index i
		int[] p = new int[inp.length];
		p[0] = inp[0];
		for (int i = 1; i < inp.length; i++) {
			p[i] = p[i - 1] + inp[i];
		}

		// array Q from the description below
		int[] q = new int[inp.length];
		q[inp.length - 1] = p[inp.length - 1];
		for (int i = inp.length - 2; i >= 0; i--) {
			q[i] = Math.max(q[i + 1], p[i]);
		}
		int a = 0;
		int b = 0;
		int maxLen = 0;
		int curr;
		int[] res = new int[] { -1, -1 };
		while (b < inp.length) {
			curr = a > 0 ? q[b] - p[a - 1] : q[b];
			if (curr >= 0) {
				if (b - a > maxLen) {
					maxLen = b - a;
					res = new int[] { a, b };
				}
				b++;
			} else {
				a++;
			}
		}
		return res;
	}

	static void factor(int n) {
		if (si[n] == n) {
			f.add(n);
			return;
		}
		f.add(si[n]);
		factor(n / si[n]);
	}

	static void seive() {
		si = new int[100001];
		primes = new ArrayList<>();
		int N = 100001;
		si[1] = 1;
		for (int i = 2; i < N; i++) {
			if (si[i] == 0) {
				si[i] = i;
				primes.add(i);
			}
			for (int j = 0; j < primes.size() && primes.get(j) <= si[i] && (i * primes.get(j)) < N; j++)
				si[primes.get(j) * i] = primes.get(j);

		}
	}

	static class unionfind {
		int[] p;
		int[] size;
		int jum;

		unionfind(int n) {
			p = new int[n];
			size = new int[n];

			for (int i = 0; i < n; i++) {
				p[i] = i;
			}
			jum = n;
			Arrays.fill(size, 1);
		}

		int findSet(int v) {
			if (v == p[v])
				return v;
			return p[v] = findSet(p[v]);
		}

		boolean sameSet(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return true;
			return false;
		}

		int max() {
			int max = 0;
			for (int i = 0; i < size.length; i++)
				if (size[i] > max)
					max = size[i];
			return max;
		}

		void combine(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return;
			jum--;
			if (size[a] > size[b]) {
				p[b] = a;
				size[a] += size[b];

			} else {
				p[a] = b;
				size[b] += size[a];
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


import java.util.*;
import java.io.*;

public class DIYGarland
{

	public static void main(String[] args)
	{
		JS scan = new JS();
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt();
		int[] arr = new int[n];
		int[] val = new int[n];
		int[] deg = new int[n];
		for(int i = 0; i < n-1; i++) {
			arr[i] = scan.nextInt()-1;
			val[i] = i;
			deg[arr[i]]++;
		}
		PriorityQueue<Node> pq = new PriorityQueue<Node>();
		for(int i = 0; i < n; i++) {
			if(deg[i] == 0) {
				pq.add(new Node(i, val[i]));
			}
		}
		out.print(arr[0]+1);
		out.println();
		for(int i = n-2; i >= 0; i--) {
			Node p = pq.poll();
			int x = arr[i];
			val[x] = Math.max(val[x], p.val);
			out.println((x+1)+" "+(p.i+1));
			deg[x]--;
			if(deg[x] == 0) {
				pq.add(new Node(x, val[x]));
			}
		}
		out.flush();
	}

	static class Node implements Comparable<Node>{

		int i;
		int val;

		public Node(int i, int val) {
			this.i = i;
			this.val = val;
		}

		@Override
		public int compareTo(Node arg0)
		{
			return this.val-arg0.val;
		}
	}

	static class JS{
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}

		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}
}


import java.util.*;
import java.io.*;

/*
5
3 2 3 2
 */

public class DIYGarland
{

	public static void main(String[] args)
	{
		JS scan = new JS();
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt();
		int[] arr = new int[n];
		int[] val = new int[n];
		int[] deg = new int[n];
		for(int i = 0; i < n-1; i++) {
			arr[i] = scan.nextInt()-1;
			deg[arr[i]]++;
		}
		for(int i = 0; i < n; i++) val[i] = i;
		PriorityQueue<Node> pq = new PriorityQueue<Node>();
		for(int i = 0; i < n; i++) {
			if(deg[i] == 0) {
//				System.out.println(i+" "+val[i]);
				pq.add(new Node(i, val[i]));
			}
		}
		out.print(arr[0]+1);
		out.println();
		for(int i = n-2; i >= 0; i--) {
			Node p = pq.poll();
			int x = arr[i];
			val[x] = Math.max(val[x], p.val);
			out.println((x+1)+" "+(p.i+1));
			deg[x]--;
			if(deg[x] == 0) {
				pq.add(new Node(x, val[x]));
			}
		}
		out.flush();
	}

	static class Node implements Comparable<Node>{

		int i;
		int val;

		public Node(int i, int val) {
			this.i = i;
			this.val = val;
		}

		@Override
		public int compareTo(Node arg0)
		{
			return this.val-arg0.val;
		}
	}

	static class JS{
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}

		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}
}


//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    public static class Task {

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int rt = sc.nextInt() - 1;
            int[] a = new int[n - 2];
            for (int i = 0; i < n - 2; i++) {
                a[n - 2 - 1 - i] = sc.nextInt() - 1;
            }
            int[] deg = new int[n];
            for (int i = 0; i < n - 2; i++) {
                if (a[i] == rt) a[i] = n - 1;
                else if (a[i] > rt) a[i]--;
                deg[a[i]]++;
            }
            PriorityQueue<Integer> empty = new PriorityQueue<>(new Comparator<Integer>() {
                @Override
                public int compare(Integer o1, Integer o2) {
                    return o1 - o2;
                }
            });
            for (int i = 0; i < n; i++) if (deg[i] == 0) empty.add(i);
            List<int[]> edge = new ArrayList<>();
            for (int v: a) {
                int mn = empty.poll();
                edge.add(new int[]{v, mn});
                deg[v]--;
                if (deg[v] == 0) empty.add(v);
            }
            int rm = empty.poll();
            edge.add(new int[]{rm, n - 1});
            pw.println(rt + 1);
            for (int[] ee: edge) {
                if (ee[0] == n - 1) ee[0] = rt;
                else if (ee[0] >= rt) ee[0]++;
                ee[0]++;
                if (ee[1] == n - 1) ee[1] = rt;
                else if (ee[1] >= rt) ee[1]++;
                ee[1]++;
                pw.println(ee[0] + " " + ee[1]);
            }
        }
    }

    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("input"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("input"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}