In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.

In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.

The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.

Input

The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.

The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103). 

Output

Print a single number — the sought number of days.

Examples

Input

4
10 3 5 10


Output

5


Input

5
10 2 8 3 5


Output

5

Note

In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.

In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Iterator;


public class Main {

    /** GENERAL CONFIGURATION **/
    public static final int TIME_LIMIT = 2;
    public static final long MEMORY_LIMIT = 64 * 1024 * 1000;
    public static final int INPUT_OUTPUT = InputOutputMode.CONSOLE; 
    
    /** EXTENDS CONFIGURATION **/
    public static final String INPUT_FILE_NAME = "input.txt";
    public static final String OUTPUT_FILE_NAME = "output.txt";
    
    /** INITIALIZATION  IO **/
    public static final InputReader in = Prepare.input();
    public static final OutputWriter out = Prepare.output();
    
    
    public static void main(String[] args) throws IOException {
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.readInt();
        int[]tab = new int[n];
        for(int i = 0; i < n; i++) {
            tab[i] = in.readInt();
        }
        int days = 0;
        while (true) {
            days++;
            if (!check(tab, days)) {
                break;
            }
        }
        out.printLine(days);
    }
    
    public boolean check(int[]tab, int days) {
        boolean flag = false;
        for (int i = 0; i < tab.length; i++) {
            if (tab[i] - days <= 0) {
                if (flag == true) return false;
                else flag = true;
            }
            else {
                flag = false;
            }
        }
        if (tab[0] - days <= 0 || tab[tab.length - 1] - days <= 0) return false;
        return true;
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    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 readInt() {
        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 readLong() {
        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 String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public char readCharacter() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        return (char) c;
    }

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

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(outputStream);
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }
}

class InputOutputMode {
    public static final int CONSOLE = 0;
    public static final int FILE = 1;
}

class Prepare {
    public static InputStream input;
    public static OutputStream output;
    
    @SuppressWarnings("unused")
    public static InputReader input() {
        try {
            if (Main.INPUT_OUTPUT == InputOutputMode.CONSOLE) {
                input = System.in;
            }
            else if (Main.INPUT_OUTPUT == InputOutputMode.FILE){
                input = new FileInputStream(new File(Main.INPUT_FILE_NAME));
            }
        }
        catch (IOException ex)
        {
            System.err.println("Some problem with input settings.");
            System.exit(0);
        }
        return new InputReader(input);
    }
    @SuppressWarnings("unused")
    public static OutputWriter output() {
        try {
            if (Main.INPUT_OUTPUT == InputOutputMode.CONSOLE) {
                output = System.out;
            }
            else if (Main.INPUT_OUTPUT == InputOutputMode.FILE){
                output = new FileOutputStream(new File(Main.OUTPUT_FILE_NAME));
            }
        }
        catch (IOException ex) {
            System.err.println("Some problem with output settings.");
            System.exit(0);
        }
        return new OutputWriter(output);
    }
}