n=int(input())
s=input().split()
for i in range(n):s[i]=int(s[i])
money=sum(s)
s1=s
while max(s1)>0:
    if max(s1)!=max(s):
        money-=1
        s=s1
    s1=s1[:-1:]
    if len(s1)==0:break
if len(s1)!=0:money-=sum(s[1])
print(money)