N, K = map(int, input().split())
N -= 1
S = []
for i in range(K):
    L, R = map(int, input().split())
    for j in range(L, R+1):
        S.append(j)
S = sorted(S)

dp = [0]*N

for i in range(N):
    for j in range(i):
        if i-j in S:
            dp[i] += dp[j]
    if i+1 in S:
        dp[i] += 1

print(dp[N-1]%998244353)
