#!/usr/bin/env python3
import sys
from decimal import Decimal

MOD = 998244353  # type: int


def solve(N: int, K: int, L: "List[int]", R: "List[int]"):
    routes = [0 for _ in range(N)]
    # routes[0] = Decimal(1)
    routes[0] = 1
    moves = []

    c = []
    for k in range(K):
        c.append([L[k], R[k]])
    c = sorted(c)
    for k in c:
        moves += list(range(k[0], k[1]+1))

    moves = sorted(moves)
    for i in range(1, N):
        tmp = 0
        for m in moves:
            if i < m: break
            # tmp += Decimal(routes[i - m])
            tmp += (routes[i - m])
            # print(i, m, tmp)
        routes[i] = tmp % MOD
    # print(routes)
    return routes[N-1] % MOD


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    L = [int()] * (K)  # type: "List[int]"
    R = [int()] * (K)  # type: "List[int]"
    for i in range(K):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    print(solve(N, K, L, R))

if __name__ == '__main__':
    main()
