mod=998244353 n=int(input()) a=list(map(int,input().split())) ans=1 for i in range(n-1): ans*=min(a[i],a[i+1]) ans%=mod print(ans)