N,K = map(int,input().split())
cc = [list(map(int,input().split())) for i in range(K)]
masu = [1]+[0]*(N-1)
ccc = []
for i,j in cc:
  for k in range(i,j+1):
    ccc.append(k)
ccc.sort()
for i in range(N):
  for j in ccc:
    if i-j>=0:
      if masu[i-j]!=0:
        masu[i]+=masu[i-j]
    else:
      break
print(masu[-1]%998244353)
