Problem:
Score : 1300 points

Problem Statement

We have a pyramid with N steps, built with blocks.
The steps are numbered 1 through N from top to bottom.
For each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally.
The pyramid is built so that the blocks at the centers of the steps are aligned vertically.

A pyramid with N=4 steps

Snuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.
Then, he wrote integers into all remaining blocks, under the following rule:

The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.

Writing integers into the blocks

Afterwards, he erased all integers written into the blocks.
Now, he only remembers that the permutation written into the blocks of step N was (a_1, a_2, ..., a_{2N-1}).

Find the integer written into the block of step 1.

Constraints

2≤N≤10^5

(a_1, a_2, ..., a_{2N-1}) is a permutation of (1, 2, ..., 2N-1).

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{2N-1}

Output

Print the integer written into the block of step 1.

Sample Input 1

4
1 6 3 7 4 5 2

Sample Output 1

4

This case corresponds to the figure in the problem statement.

Sample Input 2

2
1 2 3

Sample Output 2

2

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int A[] = new int[2 * N - 1];
            for (int i = 0; i < 2 * N - 1; i++) {
                A[i] = in.nextInt();
            }

            int lo = 0, hi = 2 * N;

            while (lo + 1 < hi) {
                int mid = lo + (hi - lo) / 2;

                if (onTopAtLeast(mid, A)) {
                    lo = mid;
                } else {
                    hi = mid;
                }
            }

            out.println(lo);
        }

        private boolean onTopAtLeast(int x, int[] a) {
            int LEN = a.length; // LEN = 2*N-1
            int N = (LEN + 1) / 2;
            int[] b = new int[2 * N - 1];
            for (int i = 0; i < LEN; i++) {
                b[i] = a[i] < x ? 0 : 1;
            }
            int[] c = new int[2 * N - 1];
            for (int i = 1; i < LEN - 1; i++) {
                c[i] = b[i - 1] + b[i] + b[i + 1] < 2 ? 0 : 1;
            }

            int left = N - 1;
            int right = N - 1; //srodeczek

            while (left > 1 && c[left - 1] == c[left]) left--;
            while (right < 2 * N - 3 && c[right] == c[right + 1]) right++;//C[1, 2*N-3]

            int ANS = ((N - 1) - left < right - (N - 1)) ? c[left] : c[right];

            return ANS == 1;
        }

    }

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

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}