N, K = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(K)]

S = []
for i in range(K):
  for j in range(X[i][0], X[i][1]+1): S.append(j)

mod = 998244353
dp = [0] * N
dp[0] = 1

# N-1個目のマスまでdp
for i in range(N-1):
  for j in S:
    if 0 <= i + j <= N-1:
      dp[i+j] += dp[i]
      dp[i+j] %= mod
    else: continue

print(dp[N-1])