n, k = list(map(int, input().split()))
s = set()
o = []
for i in range(k):
    n1 = list(map(int, input().split()))
    o.append(n1)
l=[0]*(n+1)
ll = []
o.sort()
for i in o:
    for j in range(i[0],i[1]+1):
        ll.append(j)
l[0] = 1
"""
for i in range(n):
    for j in o:
        for k in range(j[0],j[1]+1):
            l[i+k] = (l[i+k]+l[i])%998244353
print(l[n-1]%998244353)
"""
lll = len(ll)
for i in range(n):
    tmp = 0
    while ll[tmp]-1 < i:
        l[i] =  l[i] + l[i-ll[tmp]]
        tmp += 1
        if lll == tmp:
            break
    l[i]=l[i]%998244353
print(l[n-1]%998244353)
