N = int(input())
P = 998244353
A = list(map(int, input().split()))

ans = 1
for i in range(N-1) :
    ans = ans * min(A[i], A[i+1]) % P
print(ans)