n = int(input()) A = list(map(int,input().split())) ans = 1 mod = 998244353 for a,na in zip(A,A[1:]): mi = min(a,na) ans *= mi ans %= mod print(ans)