n,k = map(int, input().split())

ab = [list(map(int, input().split())) for _ in range(k)]

s = []
for i in range(k):
    ss = ab[i][0]
    se = ab[i][1]
    for j in range(ss,se+1):
        s.append(j)

s.sort()

dp=[0]*(n)
dp[0] =1

for l in range(1,n):
    for m in s:
        if l-m <0:
            break
        dp[l] = (dp[l] +dp[l-m]) % 998244353 

print(dp[n-1]%998244353 )