import itertools
import math

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)


N, K = input().split()
N = int(N)
K = int(K)

kukan = []
for i in range(K):
    a,b=input().split()
    kukan.append((int(a), int(b)))

S = []
for i in range(K):
    for k in range(kukan[i][0],kukan[i][1]+1):
        S.append(k)

# 計N-1回の移動
# 集合Sから重複有りで数を選び，その和がN-1となればよい

i = 1
ans = 0

while True:
    h = itertools.product(S, repeat=i)
    flag = 0
    length = 0
    for v in h:
        length += 1
        s = sum(v)
        if s == N-1:
            ans += 1
        elif s > N-1:
            flag += 1
    if flag == length:
        break

    i += 1

print(ans%998244353)
