import sys
sys.setrecursionlimit(10**9)
mod=998244353
N,K=map(int,input().split())
_S=[]
for _ in range(K):
    l,r=map(int,input().split())
    _S+=list(range(l,r+1))
S=sorted(_S)
dp=[0]*(N+1)
def Leaping_Tak(n,S):
    x=0
    if n==0:
        return 1
    if 0<n<S[0]:
        return 0
    for s in range(S):
        if n-s > 0:
             x += Leaping_Tak(n-s,S)
    return x%mod

ans=Leaping_Tak(N-1,S)
print(ans)