/+ dub.sdl:
	name "A"
	dependency "dcomp" version=">=0.0.2"
+/

import std.algorithm, std.range, std.stdio, std.math, std.conv, core.bitop;

// import dcomp.scanner;

bool solve(bool[] a) {
    int n = (a.length.to!int + 1) / 2;

    int l = n-1;
    while (l) {
        if (a[l-1] == a[l]) break;
        l--;
    }
    int r = n-1;
    while (r < 2*n-2) {
        if (a[r] == a[r+1]) break;
        r++;
    }
    if ((n-1)-l < r-(n-1)) {
        return a[l];
    } else {
        return a[r];
    }
}

int main() {
    import std.conv;
	auto sc = new Scanner();
    int n;
    int[] a;
    sc.read(n, a);

    int l = 0, r = 2*n + 10; // x以上
    while (r-l > 1) {
        int md = (l+r)/2;
        if (solve(a.map!(a => (md <= a)).array)) {
            l = md;
        } else {
            r = md;
        }
    }
    writeln(l);
	return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File, readln, stdin;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeString, isDynamicArray;
    import std.algorithm : map;
    File f;
    this(File f = stdin) {
        this.f = f;
    }
    string[] buf;
    bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = readln.split;
        }
        return true;
    }
    int read(Args...)(auto ref Args args) {
        foreach (i, ref v; args) {
            if (!succ()) return i;
            alias VT = typeof(v);
            static if (!isSomeString!VT && isDynamicArray!VT) {
                v = buf.map!(to!(ElementType!VT)).array;
                buf.length = 0;
            } else {
                v = buf.front.to!VT;
                buf.popFront();
            }
        }
        return args.length;
    }
}
