import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict
 
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
 
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
 
def main():
    N, K = NMI()
    A = list(sorted([NLI() for _ in range(K)]))
    
    ls = [0 for _ in range(N+A[-1][1]+10)]
    ls[0] = 1
 
    for n in range(N):
        for k in range(K):
            for x in range(A[k][0],A[k][1]+1):
                ls[n+x] += ls[n]%MOD2
    print(ls[N-1]%MOD2)
if __name__ == '__main__':
    main()