from itertools import accumulate N=int(input()) P=list(map(int,input().split())) if P==[1,2]: print(0) exit() if P==[2,1]: print(1) exit() idx=[-1]*N for i in range(N): idx[P[i]-1]=i+1 idx_acc=list(accumulate(idx)) ans=0 for i in range(2,N): ans=max(ans,idx_acc[i-1]-idx[i]) print(ans)