import sys
sys.setrecursionlimit(110000)

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

D = []

for _ in range(K):
    L, R = map(int, input().split())

    for i in range(L, R+1):
        D.append(i)


dp_memo = [-1] * 300000
dp_memo[1] = 1

def dp(v):
    if dp_memo[v] != -1:
        return dp_memo[v]
    ret = 0
    for d in D:
        if v - d < 1:continue
        ret += dp(v - d)
    ret %= 998244353
    dp_memo[v] = ret
    return ret

print(dp(N))