#!/usr/bin/python3
# -*- coding: utf-8 -*-
import numpy as np
n, k = map(int, input().split())
s_list = []
a_list = np.zeros(n + 1, dtype=int)
a_list[1] = 1
for i in range(k):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        s_list.append(j)
s_list.sort()
for i in range(1, n):
    for s in s_list:
        if i + s > n:
            break
        a_list[i + s] += a_list[i]
print(a_list[n] % 998244353)

