MOD = 998244353

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