import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

m = 998244353
n, k = (int(x) for x in input().split())
d = set()
for _ in xrange(k):
    l,r = (int(x) for x in input().split())
    d = d.union(range(l, r+1))
d = sorted(d)
dp = [0 for _ in xrange(n)]
dp[0] = 1
for i in xrange(n):
    for di in d:
        try:
            dp[i+di] += dp[i]
        except:
            break
        if (dp[i+di] >= m):
            dp[i+di] = dp[i+di] %m  
print(dp[-1])