import sys
def input(): return sys.stdin.readline().rstrip()

N, K = map(int, input().split())

numlist = []
for i in range(K):
    l, r = map(int, input().split())
    numlist += list(range(l,r+1))

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

for i in range(2,N+1):
    for j in numlist:
        if j >= i:
            break
        dp[i] += dp[i-j]
    
print(dp[N] % 998244353)