# Task
######
# Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. 
#
# You are given  N scores. Store them in a list and find the score of the runner-up.
#


if __name__ == '__main__':
    n = int(input())
    arr = map(int, input().split())

arr = sorted(arr, reverse=True)
# for i in range(1, len(arr)):
#     if arr[i] != arr[i-1]:
#         print(arr[i])

last_max = max(arr)
for i in range(n):
    if last_max == max(arr):
        arr.remove(max(arr))
print(max(arr))
