import numpy as np  # noqa
import numba  # noqa
from numba import njit, b1, i4, i8, f8  # noqa

m = 998244353
N, K = map(int, input().split())

jumps = []
for i in range(K):
    l, r = map(int, input().split())
    jumps.append([l, r])

jumps = np.array(jumps)


@njit((i8, i8, i8[:, :]), cache=True)
def main(N, m, jumps):
    dp = np.zeros(N + 1)
    dp[1] = 1
    for i in range(2, N + 1):
        for j in jumps:
            mn = max(0, i - j[1])
            mx = max(mn, i - j[0])
            dp[i] = (dp[i] + np.sum(dp[mn:mx + 1])) % m
    return dp[N]


print(int(main(N, m, jumps)))
