n = int(input())
a = list(map(int, input().split()))
max_int = max(a)
ans = 0
for i in range(n):
    if i == 0 and max_int:
        continue
    elif i < max_int:
        ans += 1
    elif max_int == a[i]:
        ans = 0
print(ans)
