def solve(): N=int(input()) A=list(map(int,input().split())) Mod=998244353 X=1 for i in range(N-1): X*=min(A[i], A[i+1]) X%=Mod return X #================================================== print(solve())