n,k = (int(x) for x in input().split())
s = []
for _ in range(k):
    a,b = (int(x) for x in input().split())
    s+=list(range(a,b+1))
mod = 998244353
    
l = [0]*(n)
s = sorted(s)
min_num = s[0]
for i in range(min_num,n):
    for j in s:
        if j < i:
	        l[i] += (l[i-j])
    if i in s:
        l[i] += 1
    l[i] %= mod
print(l[n-1])