N,K = map(int,input().split())
mod = 998244353
step = []
for _ in range(K):
    L,R = map(int,input().split())
    for i in range(L,R+1):
        step.append(i)
step.sort()
dp = [0]*N
dp[0] = 1
for i in range(N-1):
    for j in step:
        if i+j <= N-1:
            dp[i+j] += dp[i] %mod
            dp[i+j] %= mod
        else:
            continue
print(dp[-1])