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,readline().split())
s=set()
for i in range(k):
  l,r=map(int,readline().split())
  s |= set(range(l,r+1))
  
memo=[0]*(n+1)
memo[1]=1
def move(x):
  if memo[x]!=0:
    return memo[x]
  else:
    for j in s:
      if 1<=x-j<=n:
        memo[x]+=move(x-j)
    return memo[x]

print(move(n)%998244353)


