n,k = map(int,input().split())
l = []
r = []
for i in range(k):
    left, right = map(int,input().split())
    l.append(left)
    r.append(right)

s = set()
for i in range(k):
    lr = list(range(l[i],r[i]+1))
    tmp = set(lr)
    s = s|tmp

def iterate(start, goal, s):
    if start == goal:
        return 1
    elif start > goal:
        return 0
    else:
        res = 0
        for i in s:
            res += iterate(start+i, goal, s)
        return res

ans = iterate(1, n, s)
ans = int(ans%998244353)
print(ans)