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())
    li.append([x, y])
for i in range(n+1):
    for j, m in li:
        for l in range(j, m+1):
            if i > l:
                dp[i] = (dp[i]+dp[i-l])%c
print(dp[-1]%c)