N,K = map(int,input().split())
MOD = 998244353
S = []
for _ in range(K):
  l,r = map(int,input().split())
  for i in range(l,r+1):
    S.append(i)
S.sort()

dp = [[-1]*(N) for _ in range(len(S)+1)]
dp[0][0] = 0
for i in range(len(S)):
  for j in range(N):
    if dp[i][j] == -1:
      continue
    n = 1
    while (j + S[i]*n) < N:
      dp[i + 1][j + S[i]*n] = max(dp[i + 1][j + S[i]*n], dp[i][j] + 1)
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
      n += 1
ans = 0
for i in range(len(S)+1):
  if dp[i][N-1] != -1:
    ans += dp[i][N-1]%MOD
print(ans%MOD)