n,k = map(int,input().split())

S = []
for i in range(k):
  l,r = map(int,input().split())
  S += list(range(l,r+1))

dp = [0]*n
dp[0] = 1

for i in range(n):
  for j in S:
    if i+j < n:
      dp[i+j] += dp[i]
      dp[i+j] = dp[i+j]%998244353
      
print(dp[n-1]%998244353)