n,k = map(int, input().split())
lr = [map(int, input().split()) for _ in range(k)]
l, r = [list(i) for i in zip(*lr)]
s = []

for j in range(k):
  if l[j] == r[j]:
    s.append(l[j])
  else:
    s.extend(range(l[j], r[j]+1))
s = list(set(s))               

list1 = [0 for l in range(n)]
list1[0] = 1

for m1 in range(1,n):
  for m2 in range(len(s)):
    if s[m2] > m1:
      break
    list1[m1] += list1[m1-s[m2]]
      
print(list1[n-1]%998244353)