import sys

input = sys.stdin.readline

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

mod = 998244353
dp = [0 for _ in range(N+1)]
dp[1] = 1
for i in range(1, N):
    for s in S:
        if i + s <= N:
            dp[s+i] += dp[i]
            dp[s+i] %= mod

print(dp[N])