import sys
sys.setrecursionlimit(10**9)


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

for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        S.add(j)

dp = [0] * (N + 1)
flag = [0] * (N + 1)
dp[1] = 1

def f(n):
    if flag[n]:
        return dp[n]
    flag[n] = 1
    ret = dp[n]
    for step in S:
        ret += f(n - step) % MOD
        ret %= MOD
    dp[n] = ret
    return ret

print(f(N))
