n, k = [int(_) for _ in input().split()]
s = []
for i in range(k):
    l, r = [int(_) for _ in input().split()]
    for j in range(l, r+1):
        s.append(j)
# print(s)
dp = [0 for i in range(n)]
dp[0] = 1
# print(dp)
for i in range(n):
    for j in s:
        if i-j >= 0:
            dp[i] += dp[i-j]
    dp[i] = dp[i] % 998244353
    # print(dp)
print(dp[-1])