import sys
input = sys.stdin.readline

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

dp = [0]*(N+r_max)
dp[0] = 1

for i in range(0,N):
    for x in S:
        dp[i+x] += dp[i]

print(dp[N-1]%MOD)
