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