def dfs(i):
  global ans
  if i>n:
    return
  if i==n:
    ans += 1
    return
  for j in range(len(myList)):
    dfs(i+myList[j])

n,k = map(int,input().split())
myList = []
for i in range(k):
  l,r = map(int,input().split())
  for j in range(l,r+1):
    myList.append(j)
myList.sort()
#print(myList)
ans = 0
dfs(1)
print(ans%998244353)