public static void main(String[] args) {
		BinaryTree BT = new BinaryTree();
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Node root = null;
		for (int i = 0; i < n; i++) {
			root = BT.addToTree(root, in.nextInt());
		}
		System.out.println(findPredecessor(root, root.left).v);
	}