#!/usr/bin/env python3
import numpy as np

mod = 998244353

n, k = list(map(int, input().split()))

lr = []
# sets = set([])
for i in range(k):
    l, r = list(map(int, input().split()))
    # sets.update(set(range(l, r+1)))
    lr.append((l, r))
# print(sets)

lr.sort()

np_lists = np.zeros(n, dtype=int)
np_lists[0] = 1

# lists = [0]*n
# lists[0] = 1

for i in range(n):
    # now = lists[i]
    # for j in sets:
    #     if (i+j) < n:
    #         lists[i+j] += now
    now = np_lists[i] % mod
    for j in range(k):
        l, r = lr[j]
        if i+l >= n:
            k = j
            break
        np_lists[i+l:i+r+1] += now % mod


# print(lists[-1] % mod)
print(np_lists[-1] % mod)
