N = int(input()) A = list(map(int,input().split())) P = 998244353 now = 1 h = A[0] if A[0] <= A[1] else A[1] for i in range(2,N): a = A[i-1] b = A[i] if b <= a: now = now * h % P h = b else: now = now * h % P h = a print(now * h % P)