MOD = 998244353
n, k = map(int, input().split())
seg = [list(map(int, input().split())) for _ in range(k)]

s = [0 for _ in range(n + 1)]
s[1] = 1
for i in range(1, n):
    x = 0
    for l, r in seg:
        x += (s[max(0, i - l + 1)] - s[max(0, i - r)]) % MOD
        x %= MOD
    s[i + 1] = (s[i] + x) % MOD
print(s[-1] - s[-2])
