from numba import njit, i8
import numpy as np

n, k = map(int, input().split())
MOD = 998244353

lr = []
for _ in range(k):
    l, r = map(int, input().split())
    lr += (list(range(l, r + 1)))

lr.sort(reverse=True)
lr = np.array(lr)

dp = np.zeros(n, dtype=np.int64)
dp[0] = 1


@njit(cache=True)
def solve(n, lr, dp):
    for i in range(n - 1):
        for k in lr:
            if i + 1 - k >= 0:
                dp[i + 1] += dp[i + 1 - k]
                dp[i + 1] %= MOD
    return dp[-1]


print(solve(n, lr, dp))