//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++) {
                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 + 1, mn + 1});
                deg[v]--;
                if (deg[v] == 0) empty.add(v);
            }
            int rm = empty.poll();
            edge.add(new int[]{rm + 1, n});
            pw.println(rt + 1);
            for (int[] ee: edge) {
                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();
        }
    }
}


/**
 * BaZ :D
 */
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class ACMIND
{
    static FastReader scan;
    static PrintWriter pw;
    static long MOD = 998244353;
    static long INF = 1_000_000_000_000_000_000L;
    static long inf = 2_000_000_000;
    public static void main(String[] args) {
        new Thread(null,null,"BaZ",1<<27)
        {
            public void run()
            {
                try
                {
                    solve();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }

    static void solve() throws IOException
    {
        scan = new FastReader();
        pw = new PrintWriter(System.out,true);
        StringBuilder sb = new StringBuilder();
        int n = ni();
        int arr[] = new int[n-1];
        for(int i=0;i<n-1;i++) {
            arr[i] = ni();
        }
        ArrayList<Integer> edgesx = new ArrayList<>();
        ArrayList<Integer> edgesy = new ArrayList<>();
        TreeSet<Integer> unknown = new TreeSet<>();
        for(int i=1;i<=n;++i) {
            unknown.add(i);
        }
        for(int i=0;i<n-1 && unknown.size() > 0;++i) {
            unknown.remove(arr[i]);
            if(i+1 == n-1) {
                edgesx.add(arr[i]);
                edgesy.add((unknown.pollLast()));
            }
            else {
                if(!unknown.contains(arr[i+1])) {
                    edgesx.add(arr[i]);
                    edgesy.add((unknown.pollLast()));
                }
                else {
                    unknown.remove(arr[i+1]);
                    edgesx.add(arr[i]);
                    edgesy.add(arr[i+1]);
                }
            }
        }
        if(edgesx.size() != n-1) {
            pl(-1);
        }
        else {
            pl(arr[0]);
            for(int i=0;i<edgesx.size();++i) {
                sb.append(edgesx.get(i));
                sb.append(" ");
                sb.append(edgesy.get(i));
                sb.append("\n");
            }
            psb(sb);
        }
        pw.flush();
        pw.close();
    }
    static int ni() throws IOException
    {
        return scan.nextInt();
    }
    static long nl() throws IOException
    {
        return scan.nextLong();
    }
    static double nd() throws IOException
    {
        return scan.nextDouble();
    }
    static void pl()
    {
        pw.println();
    }
    static void p(Object o)
    {
        pw.print(o+" ");
    }
    static void pl(Object o)
    {
        pw.println(o);
    }
    static void psb(StringBuilder sb)
    {
        pw.print(sb);
    }
    static void pa(String arrayName, Object arr[])
    {
        pl(arrayName+" : ");
        for(Object o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, int arr[])
    {
        pl(arrayName+" : ");
        for(int o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, long arr[])
    {
        pl(arrayName+" : ");
        for(long o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, double arr[])
    {
        pl(arrayName+" : ");
        for(double o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, char arr[])
    {
        pl(arrayName+" : ");
        for(char o : arr)
            p(o);
        pl();
    }
    static void pa(String listName, List list)
    {
        pl(listName+" : ");
        for(Object o : list)
            p(o);
        pl();
    }
    static void pa(String arrayName, Object[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(Object o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, int[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(int o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, long[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(long o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, char[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(char o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, double[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(double o : arr[i])
                p(o);
            pl();
        }
    }
    static class FastReader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public FastReader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public FastReader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[1000000];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
            if (neg) return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead) fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null) return;
            din.close();
        }
    }
}


import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    //Into the Hardware Mode
    long mod = (long)1e9+7;
    void pre() throws Exception{}
    void solve(int TC)throws Exception{
        int n = ni();
        int[] p = new int[1+n];
        int[] a = new int[n-1], d = new int[1+n];
        for(int i = 0; i< n-1; i++){
            a[i] = ni();
            d[a[i]]++;
        }
        TreeSet<Integer> set = new  TreeSet<>();
        for(int i = 1; i<= n; i++)if(d[i]==0)set.add(i);
        for(int i = n-2; i>= 0; i--){
            if(set.isEmpty()){
                pn(-1);
                return;
            }
            p[set.pollFirst()] = a[i];
            d[a[i]]--;
            if(d[a[i]] == 0)set.add(a[i]);
        }
        pn(set.pollFirst());
        for(int i = 1; i<= n; i++){
            if(p[i] == 0)continue;
            pn(p[i]+" "+i);
        }
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    void exit(boolean b){if(!b)System.exit(0);}
    long IINF = (long)1e18;
    final int INF = (int)1e9+2, MX = (int)2e6+5;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-7;
    static boolean multipleTC = false, memory = false, fileIO = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        if(fileIO){
            in = new FastReader("C:/users/user/desktop/inp.in");
            out = new PrintWriter("C:/users/user/desktop/out.out");
        }else {
            in = new FastReader();
            out = new PrintWriter(System.out);
        }
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();
        for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

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

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

        String nextLine() throws Exception{
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    //Into the Hardware Mode
    long mod = (long)1e9+7;
    void pre() throws Exception{}
    void solve(int TC)throws Exception{
        int n = ni();
        int[] p = new int[1+n];
        int[] a = new int[n-1], d = new int[1+n];
        for(int i = 0; i< n-1; i++){
            a[i] = ni();
            d[a[i]]++;
        }
        TreeSet<Integer> set = new  TreeSet<>();
        for(int i = 1; i<= n; i++)if(d[i]==0)set.add(i);
        for(int i = n-2; i>= 0; i--){
            if(set.isEmpty()){
                pn(-1);
                return;
            }
            p[set.pollFirst()] = a[i];
            d[a[i]]--;
            if(d[a[i]] == 0)set.add(a[i]);
        }
        pn(set.pollFirst());
        for(int i = 1; i<= n; i++){
            if(p[i] == 0)continue;
            pn(p[i]+" "+i);
        }
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    void exit(boolean b){if(!b)System.exit(0);}
    long IINF = (long)1e18;
    final int INF = (int)1e9+2, MX = (int)2e6+5;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-7;
    static boolean multipleTC = true, memory = false, fileIO = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        if(fileIO){
            in = new FastReader("C:/users/user/desktop/inp.in");
            out = new PrintWriter("C:/users/user/desktop/out.out");
        }else {
            in = new FastReader();
            out = new PrintWriter(System.out);
        }
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();
        for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

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

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

        String nextLine() throws Exception{
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }
            return str;
        }
    }
}


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

import static java.lang.Math.*;

public class Main implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Main(),"Main",1<<27).start();
    }
    public void run() {
        InputReader sc = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();
        int a[] = new int[n - 1];
        int maxInd[] = new int[n];
        Arrays.fill(maxInd, -1);
        for(int i = 0; i < n - 1; ++i) {
            a[i] = sc.nextInt() - 1;
            if(maxInd[a[i]] == -1)
                maxInd[a[i]] = i;
        }

        PriorityQueue<Pair> queue = new PriorityQueue<>(new Comparator<Pair>() {
            public int compare(Pair p1, Pair p2) {
                if(p1.maxInd < p2.maxInd)
                    return -1;
                if(p1.maxInd > p2.maxInd)
                    return 1;
                return 0;
            }
        });
        for(int i = 0; i < n; ++i) {
            if(maxInd[i] == -1)
                queue.add(new Pair(i, i));
        }

        ArrayList<Edge> list = new ArrayList<>();
        int possMaxInd[] = new int[n];
        for(int i = n - 2; i >= 0; --i ) {
            Pair curP = queue.poll();
            possMaxInd[a[i]] = max(possMaxInd[a[i]], curP.maxInd);

            list.add(new Edge(a[i], curP.ind));
            if(maxInd[a[i]] == i)
                queue.add(new Pair(a[i], max(a[i], possMaxInd[a[i]])));
        }

        out.println((a[0] + 1));
        for(Edge curE : list)
            out.println(curE.u + " " + curE.v);

        out.close();
    }
    class Pair {
        int ind, maxInd;
        Pair(int a, int b) {
            ind = a;
            maxInd = b;
        }
    }
    class Edge {
        int u, v;
        Edge(int a, int b) {
            u = a + 1;
            v = b + 1;
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FDIYGarland solver = new FDIYGarland();
        solver.solve(1, in, out);
        out.close();
    }

    static class FDIYGarland {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int n = s.nextInt();
            int[] a = new int[n - 1];
            for (int i = 0; i < n - 1; i++)
                a[i] = s.nextInt() - 1;
            int k = a[0];
            ArrayList<Edge> res = new ArrayList<>();
            int[] f = new int[n];
            f[k] = 1;
            int curr = n - 1;
            while (curr >= 0 && f[curr] == 1)
                curr--;
            int prev = k;
            for (int i = 1; i < n - 1; i++) {
                if (f[a[i]] == 1) {
                    res.add(new Edge(prev, curr));
                    f[curr] = 1;
                } else {
                    res.add(new Edge(prev, a[i]));
                    f[a[i]] = 1;
                }
                while (curr >= 0 && f[curr] == 1)
                    curr--;
                prev = a[i];
            }
            res.add(new Edge(prev, curr));
            w.println(k + 1);
            for (Edge e : res) {
                w.println((e.u + 1) + " " + (e.v + 1));
            }
        }

        class Edge {
            int u;
            int v;

            Edge(int u, int v) {
                this.u = u;
                this.v = v;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


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

public class Problem_F {
	public static void main(String[] args) {
		InputReader in = new InputReader();
		StringBuilder out = new StringBuilder();

		int N = in.nextInt();
		int[] A = new int[N - 1];
		for (int i = 0; i < N - 1; i++) {
			A[i] = in.nextInt();
		}
		boolean[] chk = new boolean[N + 1];
		int now = N;
		out.append(A[0]).append('\n');
		chk[A[0]] = true;
		for (int i = 0; i < N - 1; i++) {
			while (chk[now]) {
				now--;
			}
			int x = i == N - 2 || chk[A[i + 1]] ? now : A[i + 1];
			out.append(A[i]).append(' ').append(x).append('\n');
			chk[x] = true;
		}

		System.out.print(out);
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer st;

		public InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

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

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return null;
		}

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


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

public class A {
	public static void main (String[] args) { new A(); }

	A() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int n = fs.nextInt();
		int[] a = new int[n-1];
		int[] freq = new int[n];
		for(int i = 0; i < a.length; i++) {
			a[i] = fs.nextInt()-1;
			freq[a[i]]++;
		}
		TreeSet<Integer> canBe = new TreeSet<>();
		for(int i = 0; i < n; i++) if(freq[i] == 0) canBe.add(i);

		ArrayList<Integer>[] adj = new ArrayList[n];
		for(int i = 0; i < n; i++) adj[i] = new ArrayList<>();

		int[] par = new int[n]; Arrays.fill(par, -1);
		for(int i = n-2; i >= 0; i--) {
			int v = canBe.pollFirst();
			par[v] = a[i];
			adj[a[i]].add(v);
			freq[a[i]]--;
			if(freq[a[i]] == 0) canBe.add(a[i]);
		}
		int root = -1;
		for(int i = 0; i < n; i++) {
			if(par[i] == -1) {
				root = i;
				break;
			}
		}
		out.println(root+1);
		for(int i = 0; i < n; i++) {
			for(int v : adj[i]) {
				out.println((i+1) + " " + (v+1));
			}
		}

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		FastScanner(){
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer("");
		}
		String next() {
			if(st.hasMoreTokens()) return st.nextToken();
			try { st = new StringTokenizer(br.readLine()); } catch (Exception e) {}
			return next();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FDIYGarland solver = new FDIYGarland();
        solver.solve(1, in, out);
        out.close();
    }

    static class FDIYGarland {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt();
            int[] p = new int[n], pos = new int[n + 1];
            ArrayList<pair<Integer, Integer>> a = new ArrayList<>();
            for (int i = 1; i < n; i++) {
                p[i] = s.nextInt();
                if (pos[p[i]] == 0) pos[p[i]] = i;
            }
            int[] ind = new int[n + 1];
            PriorityQueue<Integer> pq = new PriorityQueue<>();
            for (int i = 1; i <= n; i++)
                if (pos[i] == 0) {
                    pq.add(i);
                    ind[i] = i;
                }
            for (int i = n - 1; i > 0; i--) {
                int I = pq.poll();
                a.add(new pair<>(ind[I], p[i]));
                if (pos[p[i]] == i) {
                    if (I > p[i]) ind[I] = p[i];
                    else ind[p[i]] = p[i];
                    pq.add(Math.max(I, p[i]));
                }
            }
            w.println(p[0]);
            for (pair<Integer, Integer> pp : a) w.println(pp);
        }

    }

    static class pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<pair<U, V>> {
        public U x;
        public V y;

        public pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int compareTo(pair<U, V> other) {
            int i = x.compareTo(other.x);
            if (i != 0) return i;
            return y.compareTo(other.y);
        }

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

        public boolean equals(Object obj) {
            if (this.getClass() != obj.getClass()) return false;
            pair<U, V> other = (pair<U, V>) obj;
            return x.equals(other.x) && y.equals(other.y);
        }

        public int hashCode() {
            return 31 * x.hashCode() + y.hashCode();
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FDIYGarland solver = new FDIYGarland();
        solver.solve(1, in, out);
        out.close();
    }

    static class FDIYGarland {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt();
            int[] p = new int[n], pos = new int[n + 1];
            ArrayList<pair<Integer, Integer>> a = new ArrayList<>();
            for (int i = 1; i < n; i++) {
                p[i] = s.nextInt();
                if (pos[p[i]] == 0) pos[p[i]] = i;
            }
            int[] ind = new int[n + 1];
            PriorityQueue<Integer> pq = new PriorityQueue<>();
            for (int i = 1; i <= n; i++)
                if (pos[i] == 0) {
                    pq.add(i);
                    ind[i] = i;
                }
            for (int i = n - 1; i > 0; i--) {
                int I = pq.poll();
                a.add(new pair<>(ind[I], p[i]));
                if (pos[p[i]] == i) {
                    if (I > p[i]) ind[I] = p[i];
                    else ind[p[i]] = p[i];
                    pq.add(Math.max(I, p[i]));
                }
            }
            w.println(p[1]);
            for (pair<Integer, Integer> pp : a) w.println(pp);
        }

    }

    static class pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<pair<U, V>> {
        public U x;
        public V y;

        public pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int compareTo(pair<U, V> other) {
            int i = x.compareTo(other.x);
            if (i != 0) return i;
            return y.compareTo(other.y);
        }

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

        public boolean equals(Object obj) {
            if (this.getClass() != obj.getClass()) return false;
            pair<U, V> other = (pair<U, V>) obj;
            return x.equals(other.x) && y.equals(other.y);
        }

        public int hashCode() {
            return 31 * x.hashCode() + y.hashCode();
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


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

public class HelloWorld
{

  public static void main(String[] args) throws Exception
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(System.out);
    int n = Integer.parseInt(br.readLine());
    Integer[] deg = new Integer[n+1];
    for(int i = 1; i < n+1; i++)
    {
      deg[i] = 1;
    }
    StringTokenizer st = new StringTokenizer(br.readLine());
    ArrayList<Integer> ls = new ArrayList<>();
    int node = -1;
    for(int i = 1; i < n; i++)
    {
      int x = Integer.parseInt(st.nextToken());
      if(i == 1) node = x;
      deg[x]++;
      ls.add(x);
    }
    PriorityQueue<Integer> queue = new PriorityQueue<>();
    for(int i = 1; i < n+1; i++)
    {
      if(deg[i] == 1) queue.add(i);
    }
    ArrayList<Integer> ls1 = new ArrayList<>();
    ArrayList<Integer> ls2 = new ArrayList<>();
    for(int i = n-2; i >= 0; i--)
    {
      int x = ls.get(i);
      ls1.add(queue.poll());
      ls2.add(x);
      deg[x]--;
      if(deg[x] == 1) queue.add(x);
    }
    for(int i = n-2; i >= 0; i--)
    {
      writer.println(ls1.get(i) + " " + ls2.get(i));
    }
    br.close();
    writer.close();
  }

}


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

public class HelloWorld
{

  public static void main(String[] args) throws Exception
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(System.out);
    int n = Integer.parseInt(br.readLine());
    Integer[] deg = new Integer[n+1];
    for(int i = 1; i < n+1; i++)
    {
      deg[i] = 1;
    }
    StringTokenizer st = new StringTokenizer(br.readLine());
    ArrayList<Integer> ls = new ArrayList<>();
    int node = -1;
    for(int i = 1; i < n; i++)
    {
      int x = Integer.parseInt(st.nextToken());
      if(i == 1) node = x;
      deg[x]++;
      ls.add(x);
    }
    writer.println(node);
    PriorityQueue<Integer> queue = new PriorityQueue<>();
    for(int i = 1; i < n+1; i++)
    {
      if(deg[i] == 1) queue.add(i);
    }
    ArrayList<Integer> ls1 = new ArrayList<>();
    ArrayList<Integer> ls2 = new ArrayList<>();
    for(int i = n-2; i >= 0; i--)
    {
      int x = ls.get(i);
      ls1.add(queue.poll());
      ls2.add(x);
      deg[x]--;
      if(deg[x] == 1) queue.add(x);
    }
    for(int i = n-2; i >= 0; i--)
    {
      writer.println(ls1.get(i) + " " + ls2.get(i));
    }
    br.close();
    writer.close();
  }

}


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

public class HelloWorld
{

  public static void main(String[] args) throws Exception
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(System.out);
    int n = Integer.parseInt(br.readLine());
    Integer[] deg = new Integer[n+1];
    for(int i = 1; i < n+1; i++)
    {
      deg[i] = 1;
    }
    StringTokenizer st = new StringTokenizer(br.readLine());
    ArrayList<Integer> ls = new ArrayList<>();
    int node = -1;
    for(int i = 1; i < n; i++)
    {
      int x = Integer.parseInt(st.nextToken());
      if(i == 1) node = x;
      deg[x]++;
      ls.add(x);
    }
    Queue<Integer> queue = new LinkedList<>();
    for(int i = 1; i < n+1; i++)
    {
      if(deg[i] == 1) queue.add(i);
    }
    ArrayList<Integer> ls1 = new ArrayList<>();
    ArrayList<Integer> ls2 = new ArrayList<>();
    for(int i = n-2; i >= 0; i--)
    {
      int x = ls.get(i);
      ls1.add(queue.poll());
      ls2.add(x);
      deg[x]--;
      if(deg[x] == 1) queue.add(x);
    }
    for(int i = n-2; i >= 0; i--)
    {
      writer.println(ls1.get(i) + " " + ls2.get(i));
    }
    br.close();
    writer.close();
  }

}


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

public class ProblemF {

    public static InputStream inputStream = System.in;

    public static OutputStream outputStream = System.out;

    public static void main(String[] args) {
        MyScanner scanner = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = scanner.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n - 1; i++) {
            list.add(scanner.nextInt());
        }

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

        int last = list.get(0);
        visited[last] = true;
        Tree tree = new Tree(n);

        TreeSet<Integer> treeSet = new TreeSet<>();
        for (int i = 1; i <= n; i++) {
            treeSet.add(i);
        }
        treeSet.remove(last);
        for (int i = 1; i < n - 1; i++) {
            int x = list.get(i);
            if (visited[x]) {
                int p = treeSet.last();
                visited[p] = true;
                treeSet.remove(p);
                tree.addEdge(last, p);
            } else {
                tree.addEdge(last, x);
            }
            treeSet.remove(x);
            visited[x] = true;
            last = x;
        }

        tree.addEdge(last, treeSet.last());

        out.println(list.get(0));
        for (Node node : tree.nodes.values()) {
            for (Node child : node.children) {
                out.println(node.label + " " + child.label);
            }
        }

        out.flush();
    }

    private static class Tree {

        private Node root;

        private Map<Integer, Node> nodes = new HashMap<>();

        private Tree(int n) {
            for (int i = 1; i <= n; i++) {
                nodes.put(i, new Node(i));
            }
        }

        private void addNode(int label) {
            nodes.put(label, new Node(label));
        }

        private void addEdge(int x, int y) {
            nodes.get(x).children.add(nodes.get(y));
        }
    }

    private static class Node {

        private int label;

        private List<Node> children = new ArrayList<>();

        private Node(int label) {
            this.label = label;
        }
    }

    private static class MyScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        private MyScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

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

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

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

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

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

    private static class Pair<F, S> {

        private F first;

        private S second;

        public Pair() {}

        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }
    }
}


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

public class ProblemF {

    public static InputStream inputStream = System.in;

    public static OutputStream outputStream = System.out;

    public static void main(String[] args) {
        MyScanner scanner = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = scanner.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n - 1; i++) {
            list.add(scanner.nextInt());
        }

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

        int last = list.get(0);
        visited[last] = true;
        Tree tree = new Tree(n);

        TreeSet<Integer> treeSet = new TreeSet<>();
        for (int i = 1; i <= n; i++) {
            treeSet.add(i);
        }
        for (int i = 1; i < n - 1; i++) {
            int x = list.get(i);
            if (visited[x]) {
                int p = treeSet.last();
                visited[p] = true;
                treeSet.remove(p);
                tree.addEdge(last, p);
                last = x;
            } else {
                tree.addEdge(last, x);
                last = x;
            }
            treeSet.remove(x);
            visited[x] = true;
        }

        tree.addEdge(last, treeSet.last());

        out.println(list.get(0));
        for (Node node : tree.nodes.values()) {
            for (Node child : node.children) {
                out.println(node.label + " " + child.label);
            }
        }

        out.flush();
    }

    private static class Tree {

        private Node root;

        private Map<Integer, Node> nodes = new HashMap<>();

        private Tree(int n) {
            for (int i = 1; i <= n; i++) {
                nodes.put(i, new Node(i));
            }
        }

        private void addNode(int label) {
            nodes.put(label, new Node(label));
        }

        private void addEdge(int x, int y) {
            nodes.get(x).children.add(nodes.get(y));
        }
    }

    private static class Node {

        private int label;

        private List<Node> children = new ArrayList<>();

        private Node(int label) {
            this.label = label;
        }
    }

    private static class MyScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        private MyScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

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

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

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

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

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

    private static class Pair<F, S> {

        private F first;

        private S second;

        public Pair() {}

        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class ProblemF {

    public static InputStream inputStream = System.in;

    public static OutputStream outputStream = System.out;

    public static void main(String[] args) {
        MyScanner scanner = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = scanner.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n - 1; i++) {
            list.add(scanner.nextInt());
        }

        List<Integer> left = new ArrayList<>();
        List<Integer> right = new ArrayList<>();
        int root = list.get(0);
        left.add(root);
        boolean b = true;
        boolean[] visited = new boolean[n + 1];
        for (int i = 1; i < n - 1; i++) {
            if (i == n - 2 && !b) {
                left.add(list.get(i));
            } else {
                if (list.get(i).equals(root)) {
                    right.add(list.get(i));
                    b = false;
                } else {
                    if (b) {
                        left.add(list.get(i));
                    } else {
                        right.add(list.get(i));
                    }
                }
            }
            visited[list.get(i)] = true;
        }

        for (int i = 1; i <= n; i++) {
            if (!visited[i]) {
                left.add(i);
                visited[i] = true;
                break;
            }
        }

        for (int i = 1; i <= n; i++) {
            if (!visited[i]) {
                if (right.isEmpty()) {
                    left.add(i);
                } else {
                    right.add(i);
                }
                visited[i] = true;
                break;
            }
        }

        out.println(root);
        for (int i = 0; i < left.size() - 1; i++) {
            out.println(left.get(i) + " " + left.get(i + 1));
        }
        for (int i = 0; i < right.size() - 1; i++) {
            out.println(right.get(i) + " " + right.get(i + 1));
        }

        out.flush();
    }

    private static class MyScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        private MyScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

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

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

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

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

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

    private static class Pair<F, S> {

        private F first;

        private S second;

        public Pair() {}

        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class ProblemF {

    public static InputStream inputStream = System.in;

    public static OutputStream outputStream = System.out;

    public static void main(String[] args) {
        MyScanner scanner = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = scanner.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n - 1; i++) {
            list.add(scanner.nextInt());
        }

        List<Integer> left = new ArrayList<>();
        List<Integer> right = new ArrayList<>();
        int root = list.get(0);
        left.add(root);
        boolean b = true;
        boolean[] visited = new boolean[n + 1];
        for (int i = 1; i < n - 1; i++) {
            if (list.get(i).equals(root)) {
                right.add(list.get(i));
                b = false;
            } else if (b) {
                left.add(list.get(i));
            } else {
                right.add(list.get(i));
            }
            visited[list.get(i)] = true;
        }

        for (int i = 1; i <= n; i++) {
            if (!visited[i]) {
                left.add(i);
                visited[i] = true;
                break;
            }
        }

        for (int i = 1; i <= n; i++) {
            if (!visited[i]) {
                if (right.isEmpty()) {
                    left.add(i);
                } else {
                    right.add(i);
                }
                visited[i] = true;
                break;
            }
        }

        out.println(root);
        for (int i = 0; i < left.size() - 1; i++) {
            out.println(left.get(i) + " " + left.get(i + 1));
        }
        for (int i = 0; i < right.size() - 1; i++) {
            out.println(right.get(i) + " " + right.get(i + 1));
        }

        out.flush();
    }

    private static class MyScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        private MyScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

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

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

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

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

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

    private static class Pair<F, S> {

        private F first;

        private S second;

        public Pair() {}

        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }
    }
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;

public class Main {

	InputStream is;
	PrintWriter out;
	String INPUT = "";

	private static final long M = 1000000007L;

	void solve() {
		StringBuffer sb = new StringBuffer();
		int N = ni();
		int[] a = na(N - 1);
		boolean visited[] = new boolean[N + 1];
		List<Integer>[] g = new List[N + 1];
		for (int i = 1; i <= N; i++)
			g[i] = new ArrayList<Integer>();
		int next = N;
		int current = -1;
		for (int i : a) {
			if (!visited[i]) {
				if (current > 0)
					g[current].add(i);
			} else {
				g[current].add(next);
				visited[next] = true;
			}
			current = i;
			visited[current] = true;
			while (visited[next])
				next--;
//			tr(i, next);
		}
//		tr(visited);
		if (!visited[next])
			g[current].add(next);
//		tr(g);
		sb.append(a[0]).append(System.lineSeparator());
		for (int i=1; i<=N; i++) {
			for (int v:g[i])
				sb.append(i).append(' ').append(v).append(System.lineSeparator());
		}
		out.println(sb);

	}

	private long gcd(long a, long b) {
		while (a != 0) {
			long tmp = b % a;
			b = a;
			a = tmp;
		}
		return b;
	}

	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

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

	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 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) {
			if (!(isSpaceChar(b)))
				buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

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

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

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

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

	private Integer[][] na2(int n, int m) {
		Integer[][] a = new Integer[n][];
		for (int i = 0; i < n; i++)
			a[i] = na2(m);
		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 * 10 + (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();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}


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

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	void work() {
		int n=in.nextInt();
		TreeSet<Integer> set=new TreeSet<>();
		for(int i=1;i<=n;i++)set.add(i);
		LinkedList<Integer> queue=new LinkedList<>();
		int[] A=new int[n-1];
		for(int i=0;i<n-1;i++)A[i]=in.nextInt();
		int pre=A[0];
		set.remove(A[0]);
		int cur=set.last();
		for(int i=1;;i++) {
			if(i==n-1) {
				out.println(pre+" "+cur);
				break;
			}
			if(A[i]==cur) {
				out.println(pre+" "+cur);
				set.remove(cur);
				cur=set.last();
			}else if(set.contains(A[i])) {
				out.println(pre+" "+A[i]);
				set.remove(A[i]);
			}else {
				out.println(pre+" "+cur);
				set.remove(cur);
				cur=set.last();
			}
			pre=A[i];
		}
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

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

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

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

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


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

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	void work() {
		int n=in.nextInt();
		TreeSet<Integer> set=new TreeSet<>();
		for(int i=1;i<=n;i++)set.add(i);
		LinkedList<Integer> queue=new LinkedList<>();
		int[] A=new int[n-1];
		for(int i=0;i<n-1;i++)A[i]=in.nextInt();
		int l=A[0],r=A[0],state=0;
		queue.add(l);
		set.remove(l);
		int cur=set.last();
		for(int i=1;i<n-1;i++) {
			if(A[i]==cur) {
				if(state==0) {
					queue.addFirst(cur);
					l=cur;
				}else {
					queue.addLast(cur);
					r=cur;
				}
				set.remove(cur);
				cur=set.last();
			}else if(state==0&&A[i]==r) {
				queue.addFirst(cur);
				l=cur;
				set.remove(cur);
				cur=set.last();
				state^=1;
			}else if(state==1&&A[i]==l) {
				queue.addLast(cur);
				r=cur;
				set.remove(cur);
				cur=set.last();
				state^=1;
			}else {
				if(set.contains(A[i])) {
					set.remove(A[i]);
					if(state==0) {
						queue.addFirst(A[i]);
						l=cur;
					}else {
						queue.addLast(A[i]);
						r=cur;
					}
				}else {
					out.println(-1);
					return;
				}
			}
		}
		if(state==0) {
			queue.addFirst(cur);
		}else {
			queue.addLast(cur);
		}
		out.println(A[0]);
		int[] ret=new int[n];
		int p=0;
		for(int q:queue) {
			ret[p++]=q;
		}
		for(int i=1;i<n;i++) {
			out.println(ret[i-1]+" "+ret[i]);
		}
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

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

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

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

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


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

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	void work() {
		int n=in.nextInt();
		TreeSet<Integer> set=new TreeSet<>();
		for(int i=1;i<=n;i++)set.add(i);
		LinkedList<Integer> queue=new LinkedList<>();
		int[] A=new int[n-1];
		for(int i=0;i<n-1;i++)A[i]=in.nextInt();
		out.println(A[0]);
		int pre=A[0];
		set.remove(A[0]);
		int cur=set.last();
		for(int i=1;;i++) {
			if(i==n-1) {
				out.println(pre+" "+cur);
				break;
			}
			if(A[i]==cur) {
				out.println(pre+" "+cur);
				set.remove(cur);
				cur=set.last();
			}else if(set.contains(A[i])) {
				out.println(pre+" "+A[i]);
				set.remove(A[i]);
			}else {
				out.println(pre+" "+cur);
				set.remove(cur);
				cur=set.last();
			}
			pre=A[i];
		}
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

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

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

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

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


import java.util.*;

public class Prob1283F {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] lamps = new int[n + 1];
        for (int i = 0; i < n - 1; i++) {
            lamps[i] = in.nextInt();
            lamps[i]--;
        }
        int src = lamps[0];
        ArrayList<Integer> done = new ArrayList<>();
        System.out.println(src + 1);
        for (int i = 0; i < n; i++)
            done.add(0);
        int tmp = n - 1;
        for (int i = 0; i < n - 1; i++) {
            done.set(lamps[i], 1);
            while (done.get(tmp) != 0) {
                tmp--;
            }
            if (i == n - 2 || done.get(lamps[i + 1]) == 1) {
                System.out.println(lamps[i] + 1 + " " + (tmp + 1));
                done.set(tmp , 1);
            } else {
                System.out.println(lamps[i + 1] + 1 + " " + (lamps[i] + 1));
            }
        }
    }
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    int a[n-1];
    // rep(i,n-1)cin >> a[i];

    rep(i,n-1) scanf("%d", &a[i]);

    int par[n+1] = {};
    int son[n+1] = {};
    rep(i,n+1)son[i] = 1001001001;
    int use[n+1] = {};

    int ma = -1;
    int leaf = -1;

    rep(i,n-1){
        // cout << i << endl;
        if(i == 0){
            if(a[i] == n){
                son[a[i]] = min(son[a[i]], n-1);
                ma = n - 2;
                use[n] = 1;
                use[n-1] = 1;
                leaf = n- 1;
                par[n-1] = n;
            }else{
                son[a[i]] = n;
                par[n] = a[i];
                ma = n - 1;
                use[n] = 1;
                use[a[i]] = 1;
                leaf = n;
            }
            continue;
        }

        while(use[ma])ma--;

        if(use[a[i]] == 1){
            if(ma == 0){
                cout << "-1" << endl;
                return 0;
            }
            son[a[i]] = ma;
            par[ma] = a[i];
            use[ma] = 1;
            leaf = ma;
        }else{
            // leaf の上に挿入
            use[a[i]] = 1;
            par[a[i]] = par[leaf];
            son[a[i]] = leaf;
            par[leaf] = a[i];
        }

    }

    cout << a[0] << endl;

    srep(i,1,n+1){
        if(par[i] != 0){
            printf("%d %d\n", par[i], i);
            // cout << par[i] << ' ' << i << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    int a[n-1];
    // rep(i,n-1)cin >> a[i];

    rep(i,n-1) scanf("%d", &a[i]);

    int par[n+1] = {};
    int son[n+1] = {};
    rep(i,n+1)son[i] = 1001001001;
    int use[n+1] = {};

    int ma = -1;
    int leaf = -1;

    rep(i,n-1){
        // cout << i << endl;
        if(i == 0){
            if(a[i] == n){
                son[a[i]] = min(son[a[i]], n-1);
                ma = n - 2;
                use[n] = 1;
                use[n-1] = 1;
                leaf = n- 1;
                par[n-1] = n;
            }else{
                son[a[i]] = n;
                par[n] = a[i];
                ma = n - 1;
                use[n] = 1;
                use[a[i]] = 1;
                leaf = n;
            }
            continue;
        }

        while(use[ma])ma--;

        if(use[a[i]] == 1){
            if(ma == 0){
                cout << "-1" << endl;
                return 0;
            }
            son[a[i]] = ma;
            par[ma] = a[i];
            use[ma] = 1;
            leaf = ma;
        }else{
            // leaf の上に挿入
            use[a[i]] = 1;
            par[a[i]] = par[leaf];
            son[a[i]] = leaf;
            par[leaf] = a[i];
        }

    }

    cout << a[0] << endl;

    srep(i,1,n+1){
        if(par[i] != 0){
            cout << par[i] << ' ' << i << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    int a[n-1];
    rep(i,n-1)cin >> a[i];

    int par[n+1] = {};
    int son[n+1] = {};
    rep(i,n+1)son[i] = 1001001001;
    int use[n+1] = {};

    int ma = -1;
    int leaf = -1;

    rep(i,n-1){
        // cout << i << endl;
        if(i == 0){
            if(a[i] == n){
                son[a[i]] = min(son[a[i]], n-1);
                ma = n - 2;
                use[n] = 1;
                use[n-1] = 1;
                leaf = n- 1;
                par[n-1] = n;
            }else{
                son[a[i]] = n;
                par[n] = a[i];
                ma = n - 1;
                use[n] = 1;
                use[a[i]] = 1;
                leaf = n;
            }
            continue;
        }

        while(use[ma])ma--;

        if(use[a[i]] == 1){
            if(ma == 0){
                cout << "-1" << endl;
                return 0;
            }
            son[a[i]] = ma;
            par[ma] = a[i];
            use[ma] = 1;
            leaf = ma;
        }else{
            // leaf の上に挿入
            use[a[i]] = 1;
            par[a[i]] = par[leaf];
            son[a[i]] = leaf;
            par[leaf] = a[i];
        }

    }

    cout << a[0] << endl;

    srep(i,1,n+1){
        if(par[i] != 0){
            cout << par[i] << ' ' << i << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n - 1; ++i) {
        cin >> a[i];
        --a[i];
    }

    cout << a[0] + 1 << endl;
    vector<int> check(n);
    int cur = n - 1;
    for (int i = 0; i < n - 1; ++i) {
        check[a[i]] = true;
        if (i == n - 2 || check[a[i + 1]]) {
            while (check[cur]) --cur;
            cout << a[i] + 1 << " " << cur + 1 << endl;
        } else {
            cout << a[i] + 1 << " " << a[i + 1] + 1 << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n - 1; ++i) {
        cin >> a[i];
        --a[i];
    }

    cout << a[0] + 1 << endl;
    vector<int> check(n);
    int cur = n - 1;
    for (int i = 0; i < n - 1; ++i) {
        check[a[i]] = true;
        if (i == n - 2 || check[a[i + 1]]) {
            while (check[cur]) --cur;
            cout << a[i] + 1 << " " << cur + 1 << endl;
            check[cur] = true;
        } else {
            cout << a[i] + 1 << " " << a[i + 1] + 1 << endl;
        }
    }

    return 0;
}


#include "bits/stdc++.h"

#define pb push_back
#define f first
#define s second

using namespace std;

int n, tg;
set<int> un;
set<pair<int, int>> uf;
vector<int> v;
vector<pair<int, int>> res;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    v.assign(n - 1, 0);
    for(int i = 0; i < n - 1; ++i){
        cin >> v[i];
        v[i]--;
        un.insert(-i);
    }
    un.insert(-n + 1);
    tg = v[0];
    uf.insert({0, v[0]});
    un.erase(-v[0]);
    int pos = 1;
    while(pos < v.size()){
        if(un.find(-v[pos]) != un.end()){
            res.pb({uf.begin()->s, v[pos]});
            uf.erase(uf.begin());
            un.erase(-v[pos]);
        }
        uf.insert({pos, v[pos]});
        pos++;
    }
    cout << un.size() << " " << uf.size() << "\n";
    if(un.size() != uf.size()){
        cout << -1;
        return 0;
    }
    while(un.size()){
        res.pb({-1 * (*un.begin()), uf.begin()->s});
        uf.erase(uf.begin());
        un.erase(un.begin());
    }
    cout << tg + 1 << "\n";
    for(auto i : res){
        cout << i.f + 1 << " " << i.s + 1 << "\n";
    }
    return 0;
}


#include "bits/stdc++.h"

#define pb push_back
#define f first
#define s second

using namespace std;

int n, tg;
set<int> un;
set<pair<int, int>> uf;
vector<int> v;
vector<pair<int, int>> res;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    v.assign(n - 1, 0);
    for(int i = 0; i < n - 1; ++i){
        cin >> v[i];
        v[i]--;
        un.insert(-i);
    }
    un.insert(-n + 1);
    tg = v[0];
    uf.insert({0, v[0]});
    un.erase(-v[0]);
    int pos = 1;
    while(pos < v.size()){
        if(un.find(-v[pos]) != un.end()){
            res.pb({uf.begin()->s, v[pos]});
            uf.erase(uf.begin());
            un.erase(-v[pos]);
        }
        uf.insert({pos, v[pos]});
        pos++;
    }
    // cout << un.size() << " " << uf.size() << "\n";
    if(un.size() != uf.size()){
        cout << -1;
        return 0;
    }
    while(un.size()){
        res.pb({-1 * (*un.begin()), uf.begin()->s});
        uf.erase(uf.begin());
        un.erase(un.begin());
    }
    cout << tg + 1 << "\n";
    for(auto i : res){
        cout << i.f + 1 << " " << i.s + 1 << "\n";
    }
    return 0;
}


#include "bits/stdc++.h"

#define pb push_back
#define f first
#define s second

using namespace std;

int n;
map<int, int> m;
set<int> s;
vector<pair<int, int>> res;
vector<int> a;
vector<bool> vis;
int main(){
    cin >> n;
    a.assign(n - 1, 0);
    vis.assign(n, 0);
    for(int i = 0; i < n - 1; ++i){
        cin >> a[i];
        a[i]--;
        if(!vis[a[i]]){
            vis[a[i]] = true;
            m[a[i]] = i;
        }
    }
    for(int i = 0; i < n; ++i){
        if(!vis[i]) s.insert(i);
    }
    for(int i = n - 2; i >= 0; --i){
        res.pb({a[i], *s.begin()});
        s.erase(s.begin());
        if(m[a[i]] == i) s.insert(a[i]);
    }
    cout << a[0] + 1 << "\n";
    for(auto i : res){
        cout << i.f + 1 << " " << i.s + 1 << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define MAX 200001
struct Node
{
    int node;
    long long int importance;
    Node(int n,long long int imp)
    {
        node=n;
        importance=imp;
    }
};
bool operator<(Node A,Node B)
{
    return A.importance>B.importance;
}
int entry[MAX];
long long int value[MAX];
int main()
{
    int n,i,j;
    scanf("%d",&n);
    int parents[n-1],child[n-1];
    priority_queue<Node>pq;
    for(i=0;i<n-1;i++)
    {
        value[i+1]=i+1;
        scanf("%d",&parents[i]);
        entry[parents[i]]++;
    }
    value[n]=n;
    for(i=1;i<=n;i++)
    {
        if(entry[i]==0)
        {
            pq.push(Node(i,value[i]));
        }
    }
    long long int previous=0;
    for(i=n-2;i>=0;i--)
    {
        long long int current=pq.top().importance;
        //printf("%lld\n",current);
        child[i]=pq.top().node;
        if(current<previous)
        {
            printf("-1");
            return 0;
        }
        value[parents[i]]=max(value[parents[i]],current);
        previous=current;
        entry[parents[i]]--;
        pq.pop();
        if(entry[parents[i]]==0)
        {
            pq.push(Node(parents[i],value[parents[i]]));
        }
    }
    printf("%d\n",pq.top().node);
    for(i=0;i<n-1;i++)
    {
        printf("%d %d\n",child[i],parents[i]);
    }
    return 0;
}


#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define MAX 200001
struct Node
{
    int node;
    long long int importance;
    Node(int n,long long int imp)
    {
        node=n;
        importance=imp;
    }
};
bool operator<(Node A,Node B)
{
    return A.importance>B.importance;
}
int entry[MAX];
long long int value[MAX];
int main()
{
    int n,i,j;
    scanf("%d",&n);
    int parents[n-1],child[n-1];
    priority_queue<Node>pq;
    for(i=0;i<n-1;i++)
    {
        value[i+1]=i+1;
        value[i+1]=value[i+1]*value[i+1];
        scanf("%d",&parents[i]);
        entry[parents[i]]++;
    }
    value[n]=n;
    value[n]=value[n]*value[n];
    for(i=1;i<=n;i++)
    {
        if(entry[i]==0)
        {
            pq.push(Node(i,value[i]));
        }
    }
    long long int previous=0;
    for(i=n-2;i>=0;i--)
    {
        long long int current=pq.top().importance;
        child[i]=pq.top().node;
        if(current<previous)
        {
            printf("-1");
            return 0;
        }
        value[parents[i]]=value[parents[i]]+current;
        previous=current;
        entry[parents[i]]--;
        pq.pop();
        if(entry[parents[i]]==0)
        {
            pq.push(Node(parents[i],value[parents[i]]));
        }
    }
    printf("%d\n",pq.top().node);
    for(i=0;i<n-1;i++)
    {
        printf("%d %d\n",child[i],parents[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<int> ord(n - 1);
	for(int i = 0; i < n - 1; i++) cin >> ord[i];
	map<int,int> has;
	for(int i = 0; i < n - 1; i++) has[ord[i]] = 1;
	vector<pair<int,int>> edges;
	set<pair<int,int>> leafs;
	reverse(ord.begin(), ord.end());
	auto bad = [](){
		cout << -1 << endl;
		exit(0);
	};
	const int MAX = 200200;
	vector<int> uf(MAX), mx(MAX, -1); iota(uf.begin(), uf.end(), 0);
	function<int(int)> find = [&](int x){
		if(x == uf[x]) return x;
		return uf[x] = find(uf[x]);
	};
	for(int i = 1; i <= n; i++) if(!has[i]) mx[i] = i, leafs.insert({i, i});
	for(int i = 0, j = 0; i < n - 1; i = j){
		while(j < n - 1 && ord[i] == ord[j]) j++;
		int root = find(ord[i]);
		if(mx[root] != -1 && root != find(ord.back())){
			leafs.erase({mx[root], root});
		} else {
			mx[root] = root;
		}
		if(leafs.size() < j - i) bad();
		for(int k = 0; k < j - i; k++){
			pair<int,int> son = *leafs.begin(); leafs.erase(leafs.begin());
			int rt = find(son.second);
			if(rt == root) bad();
			uf[rt] = root;
			mx[root] = max(mx[root], mx[rt]);
			edges.push_back({ord[i], son.second});
		}
		if(root != find(ord.back()))
			leafs.insert({mx[root], root});
	}
	if(!leafs.empty()) bad();
	cout << ord.back() << endl;
	for(auto e : edges){
		int u, v; tie(u, v) = e;
		cout << u << " " << v << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<int> ord(n - 1);
	for(int i = 0; i < n - 1; i++) cin >> ord[i];
	map<int,int> has;
	for(int i = 0; i < n - 1; i++) has[ord[i]] = 1;
	set<pair<int,int>> leafs;
	for(int i = 1; i <= n; i++) if(!has[i]) leafs.insert({i, i});
	vector<pair<int,int>> edges;
	reverse(ord.begin(), ord.end());
	auto bad = [](){
		cout << -1 << endl;
		exit(0);
	};
	struct union_find{
		vector<int> parent;
		int N;
		union_find(int N) : N(N) {
			clear();
		}
		void clear(){
			parent.assign(N, -1);
		}
		int find(int u){
			return (parent[u] < 0) ? u : parent[u] = find(parent[u]);
		}
		bool is_connected(int u, int v){
			return find(u) == find(v);
		}
		bool join(int u, int v){
			u = find(u);
			v = find(v);
			if (u != v){
				if (parent[u] > parent[v])
					swap(u, v);
				parent[u] += parent[v];
				parent[v] = u;
			}
			return u != v;
		}
		int size(int u){
			return -parent[find(u)];
		}
	};
	union_find uf(n + 1);
	for(int i = 0, j = 0; i < n - 1; i = j){
		while(j < n - 1 && ord[i] == ord[j]) j++;
		if(leafs.size() < j - i) bad();
		int mx = ord[i];
		for(int k = 0; k < j - i; k++){
			pair<int,int> son = *leafs.begin(); leafs.erase(leafs.begin());
			mx = max(mx, son.first);
			if(!uf.join(ord[i], son.second)) bad();
			edges.push_back({ord[i], son.second});
		}
		if(ord.back() != ord[i]){
			leafs.insert({mx, ord[i]});
		}
	}
	if(!leafs.empty()) bad();
	cout << ord.back() << endl;
	for(auto e : edges){
		int u, v; tie(u, v) = e;
		cout << u << " " << v << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<int> ord(n - 1);
	for(int i = 0; i < n - 1; i++) cin >> ord[i];
	map<int,int> has;
	for(int i = 0; i < n - 1; i++) has[ord[i]] = 1;
	set<pair<int,int>> leafs;
	for(int i = 1; i <= n; i++) if(!has[i]) leafs.insert({i, i});
	vector<pair<int,int>> edges;
	reverse(ord.begin(), ord.end());
	auto bad = [](){
		cout << -1 << endl;
		exit(0);
	};
	for(int i = 0, j = 0; i < n - 1; i = j){
		while(j < n - 1 && ord[i] == ord[j]) j++;
		if(leafs.size() < j - i) bad();
		int mx = ord[i];
		for(int k = 0; k < j - i; k++){
			pair<int,int> son = *leafs.begin(); leafs.erase(leafs.begin());
			mx = max(mx, son.first);
			edges.push_back({ord[i], son.second});
		}
		if(ord.back() != ord[i]){
			leafs.insert({mx, ord[i]});
		}
	}
	struct union_find{
		vector<int> parent;
		int N;
		union_find(int N) : N(N) {
			clear();
		}
		void clear(){
			parent.assign(N, -1);
		}
		int find(int u){
			return (parent[u] < 0) ? u : parent[u] = find(parent[u]);
		}
		bool is_connected(int u, int v){
			return find(u) == find(v);
		}
		bool join(int u, int v){
			u = find(u);
			v = find(v);
			if (u != v){
				if (parent[u] > parent[v])
					swap(u, v);
				parent[u] += parent[v];
				parent[v] = u;
			}
			return u != v;
		}
		int size(int u){
			return -parent[find(u)];
		}
	};
	union_find uf(n + 1);
	for(auto e : edges){
		int u, v; tie(u, v) = e;
		if(!uf.join(u, v)) bad();
	}
	cout << ord.back() << endl;
	for(auto e : edges){
		int u, v; tie(u, v) = e;
		cout << u << " " << v << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<int> ord(n - 1);
	for(int i = 0; i < n - 1; i++) cin >> ord[i];
	map<int,int> has;
	for(int i = 0; i < n - 1; i++) has[ord[i]] = 1;
	vector<pair<int,int>> edges;
	set<pair<int,int>> leafs;
	reverse(ord.begin(), ord.end());
	auto bad = [](){
		cout << -1 << endl;
		exit(0);
	};
	const int MAX = 200200;
	vector<int> uf(MAX), mx(MAX, -1); iota(uf.begin(), uf.end(), 0);
	function<int(int)> find = [&](int x){
		if(x == uf[x]) return x;
		return uf[x] = find(uf[x]);
	};
	for(int i = 1; i <= n; i++) if(!has[i]) mx[i] = i, leafs.insert({i, i});
	vector<int> id(MAX);
	for(int i = 0; i < n - 1; i++) id[ord[i]] = i;
	for(int i = 0, j = 0; i < n - 1; i = j){
		while(j < n - 1 && ord[i] == ord[j]) j++;
		int root = find(ord[i]);
		mx[root] = max(mx[root], root);
		if(leafs.size() < j - i) bad();
		for(int k = 0; k < j - i; k++){
			pair<int,int> son = *leafs.begin(); leafs.erase(leafs.begin());
			int rt = find(son.second);
			if(rt == root) bad();
			uf[rt] = root;
			mx[root] = max(mx[root], mx[rt]);
			edges.push_back({ord[i], son.second});
		}
		if(j - 1 == id[ord[i]])
			leafs.insert({mx[root], root});
	}
	cout << ord.back() << endl;
	for(auto e : edges){
		int u, v; tie(u, v) = e;
		cout << u << " " << v << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define PI ( acos(-1.0) )
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(int i=a ; i<=b ; i++)
#define FORD(i,a,b) for(int i=a ; i>=b ; i--)
#define INF 1000000000
#define ll long long int
#define eps (1e-8)
#define sq(x) ( (x)*(x) )
#define all(x) x.begin(),x.end()
#define flog2(n) 64 - __builtin_clzll(n) - 1
#define popcnt(n) __builtin_popcountll(n)

using namespace std;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

// void update(vector<int> used, int &maxVal) {
//     while (used[maxVal] && maxVal) maxVal--;
// }
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);

    int n;
    cin >> n;
    vector<int> used(n + 1);
    // int maxVal = n;
    set<int> s;
    FOR (i, 1, n) s.insert(i);

    int r;
    cin >> r;
    used[r] = 1;
    // update(used, maxVal);
    s.erase(r);

    vector<pair<int, int>> edges;
    int last = r;

    FOR (i, 1, n - 2) {
        int x;
        cin >> x;
        if (!used[x]) {
            edges.pb({last, x});
            used[x] = 1;
            s.erase(x);
            // update(used, maxVal);
        }
        else {
            int maxVal = *(--s.end());

            edges.pb({last, maxVal});
            used[maxVal] = 1;
            // update(used, maxVal);
            s.erase(maxVal);
        }
        last = x;
    }
    edges.pb({last, *(s.begin())});

    cout << r << '\n';
    for (auto e: edges) {
        cout << e.first << " " << e.second << '\n';
    }

    return 0;
}