#!/usr/bin/env python
# TLE

n, k = map(int, input().split())
L = [0 for _ in range(k)]
R = [0 for _ in range(k)]
for i in range(k):
    L[i], R[i] = map(int, input().split())
mod = 998244353

dp = [0 for _ in range(n+1)]
dp[0] = 0 
dp[1] = 1 

def cont(x, y): 
    ret = []
    for i in range(x, y+1):
        ret.append(i)
    return ret 

s = []
for i in range(k):
    s += cont(L[i], R[i])

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

print(dp[n]%mod)
