import sys

def input(): return sys.stdin.readline().rstrip("\r\n")
def List(): return list(map(int, input().split()))
def Num(): return int(input())


MOD = 998244353


def countWays(arr, m, N):
    count = [0 for i in range(N + 1)]
    count[0] = 1
    for i in range(1, N + 1):
        for j in range(m):
            if i >= arr[j]:
                count[i] += count[i - arr[j]]
    return count[N]


n, k = List()
s = set()
for i in range(k):
    a, b = List()
    for ele in range(a, b + 1):
        s.add(ele)
s = list(s)
# print(s)
print(countWays(s, len(s), n - 1) % MOD)
