n, k = map(int, input().split())
s = set()
lr = []
for _ in range(k):
    # l, r = map(int, input().split())
    lr.append(tuple(map(int, input().split())))
    # for tmp in range(l, r+1):
    #     s.add(tmp)
mod = 998244353

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

for i in range(1, n):
    for l, r in lr:
        for ss in range(l, r+1):
            if i-ss >= 0:
                dp[i] += dp[i-ss]
    dp[i] %= mod

print(dp[-1]%mod)