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

LR = [map(int, input().split()) for _ in range(K)]
MOD = 998244353
dic = []
for l, r in LR:
    tmp = [x for x in range(l, r+1)]
    dic += tmp
dic.sort()
dp = [0]*(N+1)
dp[1] = 1
n = len(dic)
cnt = 0
t = []
for i in range(2, N+1):
    tmp = i-1
    while cnt < n:
        if dic[cnt] <= tmp:
            t.append(dic[cnt])
            cnt += 1
        else:
            break
    for s in t:
        dp[i] += dp[i-s]
        dp[i] %= MOD
print(dp[-1])
