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