N, K = map(int, input().split())
D = []
MOD = 998244353

for i in range(K):
    l, r = map(int, input().split())
    D.append((l, r))

dp = [0] * N
dp[0] = 1
for i in range(1, N):
    dpi = 0
    for l, r in D:
        if i - l < 0:
            continue
        r = max(0, i - r)
        l = max(0, i - l + 1)
        dpi += sum(dp[r:l])
    dp[i] = dpi % MOD

print(dp[N-1])
