m,n=map(int,input().split()) a = list(map(int, input().split())) score = 0 now = 1 smallMOD = 998244353 for i in range(n): k = a[i] - now score += k * (k + 1) * (2 * k + 1) // 6 score %= smallMOD now = a[i] + 1 k = m + 1 - now score += k * (k + 1) * (2 * k + 1) // 6 score %= smallMOD print(score)