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

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

# O(N)で解く！
# N-1個目のマスまでdp
for i in range(N-1):
  for j in range(K):
    for k in range(X[j][0], X[j][1]+1):
      if 0 <= i + k <= N-1:
        dp[i+k] += dp[i]
        dp[i+k] %= mod
      else: continue

print(dp[N-1])