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)]
    ls[0] = 1

    for n in range(1,N):
        for k in range(K):
            for x in range(A[k][0],A[k][1]+1):
                if 0 <= n-x and n-x <= N:
                    ls[n] += ls[n-x]
                    ls[n] = ls[n]%MOD2
    print(ls[-1])
if __name__ == '__main__':
    main()