import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

n,k=map(int,input().split())
s=set()
for i in range(k):
  l,r=map(int,input().split())
  s |= set(range(l,r+1))
  
memo=[0]*(2*n)
memo[1]=1

for i in range(1,n):
  for j in s:
    if i+j<n+1:
      memo[i+j]+=memo[i]

print(memo[n]%998244353)