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

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

dp = [0]*(n+1)
dp[1] = 1

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