n,k=map(int,input().split())
S = {}
for i in range(k):
  tmp = list(map(int,input().split()))
  lr = range(tmp[0],tmp[1]+1)
  S = set(lr).union(S)

MOD = 998244353

dp = [0]*(n+1)
dp[1] = 1
for i in range(1,n+1):
  for j in S:
    if i-j > 0:
      dp[i] += dp[i-j]%MOD
print(dp[n]%MOD)