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 = [0]*n
dp[0] = 1
for i in range(n):
  for s in step:
    if i>=s:
      dp[i] += dp[i-s]
    else:
      break

print(dp[n-1]%m)