N = input() N = int(N) list = [] for i in range(N): x = input() x = int(x) list.append(x) print(list) p = list[0] #pibotを先頭の配列に設定 MAX = p if p == N: print(N - 1) else: for i in list[1:]: if p < i: if MAX < i: MAX = i if i == list[N - 1]: print(p - 1) else: print(N) break