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

# dpの高速化 => O(N)で解く
dp = [0] * N
dp[0] = 1
mod = 998244353
 
for i in range(N):
  for j in range(K):
    L = X[j][0]
    R = X[j][1]
    for k in range(L, R+1):
      if 0 <= i - k <= N-1:
        dp[i] += dp[i-k]
        dp[i] %= mod
      else: continue

print(dp[N-1])