import sys
input = sys.stdin.readline

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

for i in range(1,N):
    for l,r in S:
        if i-r>=0:
            for x in range(l,r+1):
                dp[i] += dp[i-x]
        else:
            for x in range(l,r+1):
                if i-x>=0:
                    dp[i] += dp[i-x]
                else:
                    break
print(dp[N-1]%MOD)
