# -*- coding: utf-8 -*-
# D

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)
mod = 998244353

n, k = map(int, input().split())
s = []

for i in range(k):
    l,r = map(int, input().split())
    s = s + list(range(l,r+1))

# s = list(set(s))

dp = [0] * n
dp[0] = 1

for i in range(1, n):
    for s_ in s:
        if i-s_>=0:
            dp[i] += dp[i-s_] % mod

print(dp[n-1] % mod)
