import sys
input = sys.stdin.readline

N,K = map(int,input().split())
S = []
MOD = 998244353
for i in range(K):
    l,r = map(int,input().split())
    for x in range(l,r+1):
        S.append(x)
S.sort()
dp = [0]*N
dp[0] = 1

for i in range(0,N):
    for x in S:
        if i+x<=N-1:
            dp[i+x] += dp[i]
        else:
            break

print(dp[N-1]%MOD)
