n, k = map(int,input().split())
dp = [0]*(n+1)
dp[1] = 1
li = []
c = 998244353
for _ in range(k):
    x, y = map(int, input().split())
    for i in range(x, y+1):
        if i not in li:
            li.append(i)
for i in range(n+1):
    for j in li:
        if i > j:
            dp[i] = (dp[i]+dp[i-j])
print(dp[-1]%c)