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