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*2)
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)
