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

S = []
r = 998244353
for i in range(K):
    L,R = list(map(int,input().split()))
    for k in range(L,R+1):
        S.append(k)
        
        
dp = [0]*(N+1)
dp[1] = 1

for i in range(2,N+1):
    # print("i=",i)
    for k in S:
        if k<i:
            dp[i] += dp[i-k]
    dp[i] %= r
# print(S)
# print(dp)
print(dp[-1])