import sys
input = sys.stdin.readline
N,K = map(int,input().split())
figs = set()
for _ in [0] * K:
  a,b = map(int,input().split())
  for i in range(a,b+1):
    figs.add(i)
DP = [0]*N
DP[0] = 1
for i in range(N):
  for item in figs:
    if i - item >= 0:
      DP[i] = DP[i - item]+DP[i]
print(DP[-1]%998244353)