import sys
import itertools

N, K = map(int, input().split())
S = set()

dp = [0] * (N) 
dp[0]=0
q = []


for i in range(K):
    a, b = map(int, input().split())
    for j in range(a-1, b):
        dp[j+1] = 1
        q.append(j+1)

q = sorted(q)

for i in range(1, N):
    for j in q:
        if i - j < 1:
            break
        dp[i] = dp[i] + dp[i-j]
    # if i > 6:
    #     exit()

print(dp[N-1] % 998244353)