# -*- coding: utf-8 -*-

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

MOD=998244353
D=[0]*(N+1)
D[1]=1

S=[]
for i in range(K):
    L,R=map(int,input().split())
    S+=[i for i in range(L,R+1)]
    S.sort()

for i in range(2,N+1):
    for j in S:
        if j >i: break
        D[i]+=D[i-j]
    D[i]%=998244353

#print(S)
print(D[N])