n, k = list(map(int, input().split()))

lr = [list(map(int, input().split())) for _ in range(k)]

MOD = 998244353

dp = [0] * (n+1)
dp[1] = 1

for i in range(1, n+1):
    for l, r in lr:
        for j in range(l, r+1):
            if i - j >= 0:
                dp[i] = (dp[i] + dp[i-j]) % MOD
            else:
                break

#print(dp)
print(dp[n] % MOD)