import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd,log from math import sqrt, ceil from bisect import bisect_left, bisect_right from typing import Iterable input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) mod = 998244353 N = int(input()) A = li() res = 1 for i in range(N-1): res *= min(A[i],A[i+1]) res %= mod print(res)