p = 998244353
N, K = map(int, input().split())
lst = [tuple(map(int, input().split())) for i in range(K)]
lstd = []
for i in range(K):
    lstd.extend(list(range(lst[i][0], lst[i][1]+1)))

lstd.sort()

dp=[[0] * (N+1) for j in range(N+1)]
#初期化
for i in lstd:
    dp[i][1] = 1

for k in range(2, N):
    for m in range(k, N):
        for d in lstd:
            if d >= m:
                break
            else:
                dp[m][k] = (dp[m][k] + dp[m-d][k-1]) % p
answer = 0
for i in range(1, N):
    answer = (answer + dp[N-1][i]) % p
print(answer)
