import sys
import numpy as np
from numba import njit, i8

@njit((i8[:], i8, i8[:] ), cache=True)
def call(cell, n, leap):
    for i in range(n):
        if cell[i]:
            for j in leap:
                if i + j < n:
                    cell[i+j] += cell[i]
    return cell

def main():
    n, k = map(int, sys.stdin.buffer.readline().split())
    leap = set()
    cell = np.array([0]*n, np.int64)
    cell[0] = 1 
    for x in sys.stdin.buffer.readlines():
        l, r = map(int, x.split())
        leap |= set(range(l,r+1)) 
    leap = np.array(list(leap))
    c = call(cell, n, leap)
    print(c[-1]%998244353)

if __name__ == "__main__":
    main()

