n,k = map(int, input().split())
s = set()
for i in range(k):
  l,r = map(int, input().split())
  s |= {_ for _ in range(l,r+1)}
a = [0 for _ in range(4*10**5+1)]
a[1] = 1
for i in range(2*10**5):
  for d in s:
    if i+d <= 2*10**5:
      a[i+d] += a[i]%998244353
  a[i] %= 998244353
print(a[n]%998244353)