n,k=[int(c) for c in input().split()]
MOD = 998244353
segs = set()
for _ in range(k):
    a,b=[int(c) for c in input().split()]
    for i in range(a,b+1):
        segs.add(i)

dp =[0 for i in range(n)]
dp[0] = 1
# print(segs)

for i in range(n-1):
    if dp[i] != 0:
        for j in segs:
            if i + j < n:
                dp[i+j] = dp[i+j] + dp[i]
                dp[i+j]%=MOD

# print(dp)
print(dp[-1])

