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