n = int(input())
l = list(map(int,input().split()))
smaller = min(l)
smaller_index=l.index(smaller)
taller = max(l)
taller_index = l.index(taller)
largesmall = l[0]
stool=0
if(all(elem == l[0] for elem in l)):
    print(0)
else:
    for i in range(smaller_index+1):
        if(largesmall>l[i]):
            largesmall=l[i]
    for j in range(smaller_index+1):
        m=largesmall-smaller
        if(largesmall!=l[j]):
            l[j]+=m
            stool+=1
    for k in range(taller_index+1,len(l)):
        b=taller-l[k]
        l[k]+=b
        stool+=1
    print(stool+1)