import subprocess
import os
import time


import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    mod = 998244353
    n, k = map(int, input().split())

    s = {}
    for i in range(k):
        a, b = map(int, input().split())

        for x in range(a, b+1):
            s[x] = 1

    steps = list(s.keys())

    arr = [0] * (n+1)
    arr[1] = 1

    for i in range(1, n):
        if arr[i] == 0:
            continue

        for x in steps:
            if i + int(x) <= n:
                arr[i+x] += arr[i]
            else:
                break

    print(arr[n] % mod)
    

if __name__ == '__main__':
    main()
