from functools import lru_cache
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

n, k = map(int, input().split())
a = [0] * (n+1)
index = 0
for _ in range(k):
    l, r = map(int, input().split())
    for u in range(l, r+1):
        a[index] = u
        index += 1

mod = 998244353


@lru_cache(maxsize=10**8)
def calc(x):
    if x <= 0:
        return 1
    ret = 0
    for i in range(index):
        u = a[i]
        if x - u >= 0:
            ret += calc(x - u)
            ret %= mod
    return ret


print(calc(n-1))
