n = list(map(int, input().split()))
masu = [0]*n[0]
masu[0] = 1
l = [0]*n[1]
r = [0]*n[1]
for i in range(n[1]):
    kukan = list(map(int, input().split()))
    l[i] = kukan[0]
    r[i] = kukan[1]
l.sort()
r.sort()
for i in range(n[0]):
    for j in range(n[1]):
        if i + l[j] >= n[0]:
            break
        for k in range(l[j],r[j]+1):
            if i+k < n[0]:
                masu[i+k]+=masu[i]
            else:
                break
print(masu[n[0]-1]%998244353)                 