N, K = map(int, input().split())
T = []
mod = 998244353
for i in range(K):
    L, R = map(int, input().split())
    T.append([L, R])
dp = [0]*(N+1)
dp[1] = 1
Total = [0]*(N+1)
Total[1] = 1
for i in range(2, N+1):
    for j in range(K):
        L, R = T[j]
        dp[i] += Total[max(0, i-L)] - Total[max(0, i-R-1)]
    dp[i] %= mod
    Total[i] = Total[i-1] + dp[i]
    Total[i] %= mod
print(dp[N])