n, k = map(int,input().split())
lr = [map(int, input().split()) for _ in range(k)]
l, r = [list(i) for i in zip(*lr)]
step = []
for i in range(k):
  step.extend(list(range(l[i],r[i]+1)))
step.sort()

m = 998244353
dp = [-1]*n
dp[0] = 1
def solve(n):
  ans = 0
  if dp[n] != -1:
    return dp[n]
  else:
    for s in step:
      if n>=s:
        ans += solve(n-s)
      else:
        break
    dp[n] = ans
    return dp[n]
  
a = solve(n-1)
print(a%m)