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

from functools import lru_cache
#上手くいかない時は下
# from functools32 import lru_cache 

table=[0]*(N+1)
table[1]=1
step=[]
for i in range(K):
    l,r=map(int,input().split())
    for i in range(l,r+1):
        step.append(i)
        
mod=998244353
@lru_cache(None)
def leapy(x):
    if table[x] != 0:
        return table[x] 
    else:
        for y in step:
            if x>=y+1:
                if table[x-y]!=0:
                    table[x] += table[x-y]
                    table[x] %= mod
                else:
                    equ=leapy(x-y)
                    table[x] += equ
                    table[x-y] = equ
                    table[x] %= mod
        return table[x]

#type(leapy(N,table))
print(leapy(N))
#print(table)