let head3 lst =
	match lst with
	| e1 :: e2 :: e3 :: _ -> [e1; e2; e3]
	| _ -> []

let median [a; b; c] =
	let [_; m; _] = List.sort compare [a; b; c] in m

let upstairs step =
	let rec loop lst acc =
		match head3 lst with
		| [] -> acc
		| xs -> loop (List.tl lst) (xs :: acc)
	in
	loop step []
	|> List.map median

let solve step =
	let rec loop step =
		(* step is never [] *)
		match step with
		| [_] -> step
		| _ -> loop (upstairs step)
	in
	List.hd (loop step)

let () =
	let n = read_int () in
	let a =
		read_line ()
		|> Str.split (Str.regexp " ")
		|> List.map int_of_string
	in
	solve a
	|> print_int
	|> print_newline
