import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
n, k = map(int, input().split())
a = []
mod = 998244353
for i in range(k):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        a.append(j)
dp = [-1] * n
dp[0] = 1


def memo(n):
    if dp[n] >= 0:
        return dp[n]
    ans = 0
    for i in a:
        if n - i >= 0:
            ans += memo(n - i)
        else:
            break
    ans %= mod
    dp[n] = ans
    return ans


print(memo(n - 1))
