def cmb(n, r, mod):#コンビネーションの高速計算  if ( r<0 or r>n ): return 0 r = min(r, n-r) return (g1[n] * g2[r] % mod) * g2[n-r] % mod mod = 998244353#出力の制限 N = 2*10**5 g1 = [1]*(N+1) # 元テーブル g2 = [1]*(N+1) #逆元テーブル inverse = [1]*(N+1) #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod ) g2[i]=( (g2[i-1] * inverse[i]) % mod ) inverse[0]=0 import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import log,gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) def solve(N,M,A): A = [0] + A B = [0 for i in range(N+1)] for i in range(M+1): for j in range(A[i]+1,N+1): B[j] = i dp_res = [[0 for j in range(N+2)] for i in range(N+1)] dp_det_p = [[0 for j in range(N+2)] for i in range(N+1)] for i in range(1,N+1): n = B[i] for j in range(A[n],-1,-1): if i!=A[n]+1: dp_res[i][j] = (A[n+1] + (A[n]-j) * dp_res[i][j+1] + (i-A[n]) * dp_res[i-1][j]) % mod dp_res[i][j] *= inverse[i-j] dp_res[i][j] %= mod else: dp_res[i][j] = (A[n+1] + (A[n]-j) * dp_res[i][j+1] + dp_det_p[i-1][j]) % mod dp_res[i][j] *= inverse[i-j] dp_res[i][j] %= mod if i==A[n+1]: for j in range(i+1): inv = (g2[i] * g1[j] % mod) * g1[i-j] % mod for k in range(i-A[n]): dp_det_p[i][j] += ((cmb(i-A[n],k,mod) * cmb(A[n],j-k,mod) % mod) * dp_res[i-k][j-k] % mod) * inv % mod dp_det_p[i][j] %= mod dp_det_p[i][j] += (cmb(A[n],j-(i-A[n]),mod) * dp_det_p[A[n]][j-(i-A[n])] % mod) * inv % mod dp_det_p[i][j] %= mod return dp_res[N][0] N,M = mi() A = li() print(solve(N,M,A) % mod)