N=int(input()) A=list(map(int,input().split())) add=0 for i in A: add+=i add-=A[-1] ans=add+(A[-1]%A[0]) for i in range(1,N-1): ans=max(ans,add-A[i]+(A[-1]%A[i])+(A[i]%A[0])) print(ans)