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