# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 998244353
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]
S = set()

for i in range(1, N + 1):
    for lr in LR:
        l, r = lr
        if i in range(l, r + 1):
            S.add(i)
# print(S)
maxS = max(S)

# mS[n] := patterns of move +n
mS = [0] * (maxS + 1)
mS[0] = 1
for i in range(maxS):
    for s in S:
        if i + s < maxS + 1:
            mS[i + s] += mS[i]
# print(mS)
# exit()

dp = mS[:-1].copy()
dpp = []
for dpi in dp:
    dpp.append([dpi])
# print(dpp)

mat = [[0] * maxS for _ in range(maxS)]
for i in range(maxS):
    for s in S:
        if i + s - 1 < maxS:
            mat[i][i + s - 1] = 1
# pl(mat)


def mat_mul(a, b):
    I, J, K = len(a), len(b[0]), len(b)
    c = [[0] * J for _ in range(I)]
    for i in range(I):
        for j in range(J):
            for k in range(K):
                c[i][j] += a[i][k] * b[k][j]
            c[i][j] %= MOD
    return c


def mat_pow(x, n):
    y = [[0] * len(x) for _ in range(len(x))]

    for i in range(len(x)):
        y[i][i] = 1

    while n > 0:
        if n & 1:
            y = mat_mul(x, y)
        x = mat_mul(x, x)
        n >>= 1

    return y


ans = mat_mul(mat_pow(mat, N - maxS), dpp)
# pl(ans)
print(ans[0][0])