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())
    for a in range(l,r+1):
        S.append(a)

for i in range(1,N):
    for d in S:
        if i-d>=0:
            dp[i] += dp[i-d]
print(dp[N-1]%MOD)
