N,K = map(int,input().split())
S = []
for i in range(K):
    L,R = map(int,input().split())
    for j in range(L,R+1):
        S.append(j)
M = [0]*(N+1)
M[1]=1
for i in range(1,N+1):
    for LS in S:
        if LS <= i-1:
            M[i] += M[i-LS]
print(M[N] % 998244353)