n, k = map(int, input().split())
INF = 998244353
X = [list(map(int,input().split())) for _ in range(k)]
d = []
for i in range(k):
  for j in range(X[i][0],X[i][1]+1):
    d.append(j)
p = [0]*n
p[0] = 1
for i in range(1,n):
  for x in d:
    if i-x>= 0:
      p[i] += p[i-x]
print(p[-1]%INF)