def tansaku(now):
    new_masu = []
    for i in range(len(now)):
        for d in S:
            if now[i]+d == N:
                global ans
                ans += 1
            elif now[i]+d < N:
                new_masu.append(now[i]+d)

    now = new_masu
    ans %= 998244353
    if len(now) != 0:
        tansaku(now)
    else:
        print(ans)


N, K = map(int, input().split())
S = []
now = [1]
ans = 0

for i in range(K):
    L, R = map(int, input().split())
    for j in range(R-L+1):
        S.append(L+j)
S = list(set(S))
print(S)

tansaku(now)
