import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, K = MI()
    s = set()
    mod = 998244353
    for i in range(K):
        l, r = MI()
        for j in range(l, r+1):
            s.add(j)
    dp = [0] * (N+1)
    dp[1] = 1
    for i in range(1, N):
        for ss in s:
            idx = i + ss
            if idx < N+1:
                dp[i+ss] += dp[i] % mod
        # print(dp)
    # for ss in s:
    #     for i in range(ss, N, ss):
    #         dp[i] += 1
    # print(dp)
    print(dp[N] % mod)
            
if __name__ == '__main__':
    solve()

