n, k = map(int,input().split())
s = []
mod = 998244353
for i in range(k):
  l, r = map(int,input().split())
  for j in range(l,r+1):
    s.append(j)
s.sort()
cnt = [0]*n
cnt[0] = 1
for i in range(n):
  for d in range(len(s)):
    if i+s[d] <= n-1:
      cnt[i+s[d]] += cnt[i]
    elif i+s[d] > n-1:
      break
print(cnt[-1] % mod)