#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ zamenjaj(int *, int *);
int main() {
  int n, prva, druga, t;
  scanf("%d", &n);
  scanf("%d", &prva);
  scanf("%d", &druga);
  if (prva < druga) {
    zamenjaj(&prva, &druga);
  }
  for (int i = 0; i < n - 2; ++i) {
    scanf("%d", &t);
    if (t >= prva) {
      zamenjaj(&prva, &druga);
      zamenjaj(&t, &prva);
    }
    if (t > druga) {
      zamenjaj(&t, &druga);
    }
  }
  printf("%d\n", druga);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xeaa(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xe9a(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1188 <main+0x58>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <zamenjaj@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    1202 <main+0xd2>
lea    0xe59(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     11d6 <main+0xa6>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <zamenjaj@plt>
lea    -0x14(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <zamenjaj@plt>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11ef <main+0xbf>
lea    -0x14(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <zamenjaj@plt>
jmp    11f4 <main+0xc4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118f <main+0x5f>
mov    -0x10(%rbp),%esi
lea    0xdf7(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebd(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    (%rsp),%eax
jge    117e <main+0x4e>
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
call   1040 <zamenjaj@plt>
cmpl   $0x3,0xc(%rsp)
jl     11ef <main+0xbf>
xor    %ebp,%ebp
lea    0xe72(%rip),%r14
lea    0x8(%rsp),%rbx
mov    %rsp,%r15
lea    0x4(%rsp),%r12
jmp    11ae <main+0x7e>
nopl   (%rax)
add    $0x1,%ebp
mov    0xc(%rsp),%eax
add    $0xfffffffe,%eax
cmp    %eax,%ebp
jge    11ef <main+0xbf>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%eax
cmp    0x4(%rsp),%eax
jl     11dd <main+0xad>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <zamenjaj@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <zamenjaj@plt>
mov    0x8(%rsp),%eax
cmp    (%rsp),%eax
jle    11a0 <main+0x70>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <zamenjaj@plt>
jmp    11a0 <main+0x70>
mov    (%rsp),%esi
lea    0xe0a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%10 = load i32, i32* %3
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @zamenjaj(i32* %3, i32* %4)
br label %15
15: ; preds = %13, %0
store i32 0, i32* %6
br label %16
16: ; preds = %36, %15
%17 = load i32, i32* %6
%18 = load i32, i32* %2
%19 = sub nsw i32 %18, 2
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %39
21: ; preds = %16
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%23 = load i32, i32* %5
%24 = load i32, i32* %3
%25 = icmp sge i32 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @zamenjaj(i32* %3, i32* %4)
%28 = call i32 @zamenjaj(i32* %5, i32* %3)
br label %29
29: ; preds = %26, %21
%30 = load i32, i32* %5
%31 = load i32, i32* %4
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @zamenjaj(i32* %5, i32* %4)
br label %35
35: ; preds = %33, %29
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %16
39: ; preds = %16
%40 = load i32, i32* %4
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @zamenjaj(i32* %2, i32* %3)
br label %17
17: ; preds = %15, %0
%18 = load i32, i32* %1
%19 = icmp sgt i32 %18, 2
br i1 %19, label %23, label %20
20: ; preds = %39, %17
%21 = load i32, i32* %3
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
ret i32 0
23: ; preds = %17, %39
%24 = phi i32 [ %40, %39 ], [ 0, %17 ]
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%26 = load i32, i32* %4
%27 = load i32, i32* %2
%28 = icmp slt i32 %26, %27
br i1 %28, label %33, label %29
29: ; preds = %23
%30 = call i32 @zamenjaj(i32* %2, i32* %3)
%31 = call i32 @zamenjaj(i32* %4, i32* %2)
%32 = load i32, i32* %4
br label %33
33: ; preds = %29, %23
%34 = phi i32 [ %32, %29 ], [ %26, %23 ]
%35 = load i32, i32* %3
%36 = icmp sgt i32 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @zamenjaj(i32* %4, i32* %3)
br label %39
39: ; preds = %33, %37
%40 = add nuw nsw i32 %24, 1
%41 = load i32, i32* %1
%42 = add nsw i32 %41, -2
%43 = icmp slt i32 %40, %42
br i1 %43, label %23, label %20
}