N , K = map(int, input().split())

data = []
masu = [0]*(N)
masu[0] = 1

for i in range(K):
  L, R = map(int,input().split())
  if L == R:
    data.append(L)
  else:
    for j in range(L,R+1):
      data.append(j)
data.sort()
for i in range(N):
  if masu[i] >= 1:
    for j in data:
      if i+j > N-1:
        break
      else:
        masu[i+j] += masu[i]
    if masu[N-1] >= 998244353:
      masu[N-1] = masu[N-1] % 998244353
print(masu[N-1]%998244353)