import sys
input = sys.stdin.readline

n, k = map(int,input().split())
lr = []
for _ in range(k):
    l, r = map(int,input().split())
    lr.append([l, r])
lr.sort()

mod = 998244353
dp = [0]*(n+1)
dp[1] = 1

def hantei(i):
    for j in range(k):
        if i >= lr[j][0] and i <= lr[j][1]:
            return True
    return False

for i in range(2, n+1):
    for j in range(1, i):
        if hantei(i - j):
            dp[i] += dp[j]

print(dp[n] % mod)