
def input_int():
    return(int(input()))

def input_int_list():
    return(list(map(int,input().split())))

def input_int_map():
    return(map(int,input().split()))

import sys
sys.setrecursionlimit(100000000)

def run():
    n, k = input_int_map()

    k_set = set()
    for _ in range(k):
        l, r = input_int_map()

        for i in range(l, r + 1):
            k_set.add(i)

    k_list = list(k_set)

    result = find_pettern(n - 1, k_list, {})
    result = result % 998244353
    print(result)

def find_pettern(n: int, k_list: [int], memo: {}) -> int:

    if n < 0:
        return 0

    if n == 0:
        return 1

    if n in memo:
        return memo[n]

    count_num = 0
    for k in k_list:
        count_num += find_pettern(n - k, k_list, memo)

    memo[n] = count_num

    return count_num

run()
