# -*- 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 = []
l = []
r = []

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

dp = [0] * 2*n
dp[n] = 1
# print(dp)

for i in range(n+1, 2*n):
    for j in range(k):
        # print(i-r[j]+1,i-l[j]+1)
        # print(j, dp[i-r[j]+1:i-l[j]+1])
        dp[i] += sum(dp[i-r[j]+1:i-l[j]+1]) % mod
# print(dp)
print(dp[2*n-1] % mod)
