n, k = map(int, input().split())
lists = []
mod = 998244353

for i in range(k):
    tmp = tuple(map(int, input().split()))
    lists += [i for i in range(tmp[0], tmp[1] + 1)]

lists.sort()

dp = [0 for i in range(n)]
dp[0] = 1

for i in range(1, n):
    for num in lists:
        if i < num:
            break

        dp[i] += dp[i - num]
    dp[i] %= mod

print(dp[n - 1])
