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())
    S.append((l,r))

dp = [0]*(N+S[-1][1])
dp[0] = 1

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

print(dp[N-1]%MOD)
