n = int(input()) block = list(map(int, input().split(' '))) while n > 1: if block.index(n) > block.index(n-1): n -= 1 else: break print(n-1)