MOD = 998244353

N, K = map(int,input().split())
S = []
for _ in range(K):
    L, R = map(int,input().split())
    for i in range(L,R+1):
        if i not in S:
            S.append(i)

# dp[i]: マスiに移動する方法
dp = [0] * 200010
dp[0] = 1

for i in range(N):
    for d in S:
        if i+d < N:
            dp[i+d] += dp[i]
            dp[i+d] %= MOD

print(dp[N-1])
