import sys
n,k = map(int, sys.stdin.readline().rstrip("\n").split())
s = []
for _ in range(k):
    l,r = map(int, sys.stdin.readline().rstrip("\n").split())
    for i in range(l,r+1):
        s.append(i)
h = 998244353
ans = 0
c = [1]+[0]*(n-1)
for i in range(1,n):
    for j in s:
        if i-j >= 0:
            c[i] += c[i-j]
            c[i] = c[i] % h
print(c[n-1])