# region header
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
import copy
# @lru_cache(maxsize=None)
# sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
# endregion
# region input function


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


# endregion


class RAQ():
    def __init__(self, N, identity):
        """
        Parameters
        ----------
        N: int
            the number of nodes

        identity: int
            queries' identity element
            query = max -> -inf
            query = min -> inf
        """
        self.N = N
        self.depth = (N - 1).bit_length()
        self.N0 = 2 ** self.depth
        self.identity = identity
        self.init_val = 0
        self.data = [self.init_val] * (2 * self.N0)
        self.lazy = [self.init_val] * (2 * self.N0)

    def init_list(self, list):
        """init list directly

        Args:
            list (list(int)): init list
        """
        for i in range(self.N):
            self.update(i, i + 1, list[i])

    def _segfunc(self, left, right):
        res = sum([left, right])
        return res

    def _generate_index(self, l, r):
        """
        Parameters
        ----------
        l,r: int
            target range [l,r) (0-index)

        Return
        ----------
        res: iter(int)
            actually update index
        """
        L = l + self.N0
        R = r + self.N0
        lm = (L // (L & -L)) >> 1  # update target
        rm = (R // (R & -R)) >> 1
        while L < R:
            if R <= rm:
                yield R
            if L <= lm:
                yield L
            L >>= 1
            R >>= 1
        while L:
            yield L
            L >>= 1

    def _propagates(self, *ids):
        """
        Parameters
        ----------
        ids: iter(int)
            update target
        """
        for i in reversed(ids):
            v = self.lazy[i - 1]
            if not v:
                continue
            self.lazy[2 * i - 1] += v
            self.lazy[2 * i] += v
            self.data[2 * i - 1] += v
            self.data[2 * i] += v
            self.lazy[i - 1] = self.init_val

    def update(self, l, r, x):
        """
        Parameters
        ----------
        l,r: int
            target range [l,r) (0-index)
        x: int
            add value
        """
        L = self.N0 + l
        R = self.N0 + r
        while L < R:
            if R & 1:
                R -= 1
                self.lazy[R - 1] += x
                self.data[R - 1] += x
            if L & 1:
                self.lazy[L - 1] += x
                self.data[L - 1] += x
                L += 1
            L >>= 1
            R >>= 1
        for i in self._generate_index(l, r):
            self.data[i - 1] = self._segfunc(self.data[2 * i - 1], self.data[2 * i]) + self.lazy[i - 1]

    def query(self, l, r):
        """
        Parameters
        ----------
        l,r: int
            target range [l,r) (0-index)

        Return
        ----------
        res: int
        """
        self._propagates(*self._generate_index(l, r))
        L = self.N0 + l
        R = self.N0 + r

        s = self.identity
        while L < R:
            if R & 1:
                R -= 1
                s = self._segfunc(s, self.data[R - 1])
            if L & 1:
                s = self._segfunc(s, self.data[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def get_list(self):
        """get all list

        Returns:
            list(int): origin list
        """
        for i in range(self.N):
            self._propagates(*self._generate_index(i, i + 1))
        return self.data[self.N0 - 1:self.N0 + self.N - 1]


n, k = inpl()
query = []
for _ in range(k):
    l, r = inpl()
    query.append([l, r])
st = RAQ(n, 0)
st.update(n - 1, n, 1)
for i in range(n, 0, -1):
    for l, r in query:
        if i - l > 0:
            st.update(max(0, i - r - 1), i - l, st.query(i - 1, i))
print(st.query(0, 1) % 998244353)
