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

s = []
for i in range(k):
    l, r = list(map(int, input().split()))

    for j in range(l, r+1):
        s.append(j)

dp = [0] * n
dp[0] = 1
for i in range(n):
    for j in s:
        ind = i-j
        if ind >= 0:
            dp[i] += dp[ind]
            dp[i] %= 998244353

print(dp[n-1])