n, k = map(int, input().split())
s = set()
for LR in range(k):
    l, r = map(int, input().split())
    for lr in range(l, r+1):
        s.add(lr)
dp = [0]*n
dp[0] = 1
for i in range(n):
    for d in s:
        if i-d >= 0:
            dp[i] = (dp[i-d] + dp[i]) % 998244353
print(dp[n-1])