import numpy as np

MOD = 998244353

n, k = map(int,input().split())
lr = []
for i in range(k):
    l, r = map(int,input().split())
    lr.append([l,r+1])
            
dp = np.zeros(n+1, dtype=np.int64)
dp[1] = 1
for i in range(1, n+1):
    for j in range(k):
        l, r = lr[j][0], lr[j][1]
        if r > n+1-i:
            r = n+1-i
        if l > n+1-i:
            continue
        dp[i+l:i+r] += dp[i]
        dp[i+l:i+r] %= MOD
        # print(dp)
print(dp[n])