import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np
#import sympy

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    elif x == 0:
            return default
    else:
        return my_index(l,x-1)

def solve():
    #n = int(stdin.readline().rstrip())
    n,k = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    s = []
    for i in range(k):
        l,r = map(int, stdin.readline().rstrip().split())
        for j in range(l,r+1):
            s.append(j)
    s.sort()
    points = [0] * n
    points[-1] = 1
    index = 0

    for i in range(n-2,-1,-1):
        if s[0] > n-1-i:
            continue
        p=0
        for j in range(index+1):
            p += points[i+s[j]]
        points[i] = p
        if index == len(s)-1:
            continue
        elif s[index + 1] == n-i:
            index += 1

    print(points[0]%998244353)


if __name__ == '__main__':
    solve()
