import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod = 998244353
INF = 10**18
eps = 10**-7

n,k = map(int,readline().split())
vec = [0]*(n+1)
for i in range(k):
    l,r = map(int,readline().split())
    for j in range(l,r+1):
        vec[j] = 1

to = []

for i in range(1,n+1):
    if vec[i] == 1:
        to.append(i)

dp = [0]*(n+1)
dp[1] = 1
for i in range(1,n+1):
    for j in to:
        if (i+j > n):
            break
        dp[i+j] = (dp[i]+dp[i+j])%mod

print(dp[n])

