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

mod = 998244353
dp = np.zeros(N)
dp[0] = 1

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