mod = 998244353

N, K = list(map(int, input().split()))
move = []
for _ in range(K):
    L, R = list(map(int, input().split()))
    for i in range(L, R+1):
        move.append(i)
dp = [0]*(2*N+10)
dp[0] = 1
for i in range(N):
    tmp = dp[i]
    for m in move:
        dp[i+m] += tmp
        dp[i+m] %= mod
print(dp[N-1])