import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] str = br.readLine().split(" "); int n = Integer.parseInt(str[0]); String[] as = br.readLine().split(" "); int[] aArr = new int[n]; aArr[0] = Integer.parseInt(as[0]); long ans = 1; for(int i = 1 ; i < n ; i++){ aArr[i] = Integer.parseInt(as[i]); int min = Math.min(aArr[i-1] , aArr[i]); ans *= min; ans %= 998244353; } System.out.println(ans); } }