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