N, K = map(int, input().split())
MOD = 998244353
P = []
for _ in range(K):
    l, r = map(int, input().split())
    for i in range(l, r+1):
        P.append(i)
dp = [0]*(N+1)
dp[0]=1
for i in range(N):
    for p in P:
        dp[min(i+p,N)] += dp[i]
        dp[min(i + p, N)]%=MOD
print(dp[N-1])