import sys
sys.setrecursionlimit(500000)
n, k = map(int,input().split())
num = [-1]*(n+1)
num[0] = 0
num[1] = 1
s = set()
MOD = 998244353
for i in range(k):
    l, r = map(int,input().split())
    s = s | set(range(l,r+1))
def numpat(n):
    if n<0:
        return 0
    elif num[n]!=-1:
        return num[n]
    tmp = 0
    for i in s:
        tmp += numpat(n-i)
    num[n]=tmp%MOD
    return num[n]
print(numpat(n))