n,k = map(int,input().split())
w = [0]*1000000
s = []
for _ in range(k):
  l,r = map(int,input().split())
  if l==r:
    s.append(l)
  else:
    for i in range(l,r+1):
      s.append(i)
s.sort()

w[1] = 1
for i in range(2,n+1):
  for num in s:
    if i-num < 1:
      break
    w[i] += w[i-num]
print(w[n]%998244353)

