N,K = map(int, input().split())

MOD = 998244353

lst = []
for _ in range(K):
  l, r = map(int, input().split())
  for i in range(l, r+1):
    lst.append(i)
    
#print(lst)

dp = [0] * (N *2)
dp[0] = 1

for i in range(N):
  for j in lst:
    dp[i + j] += dp[i] % MOD
  #print(dp)
   
print(dp[N-1]% MOD)