FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]

####
MOD = 998244353
YES, NO, IMP = "YES", "NO", "IMPOSSIBLE"
from collections import defaultdict as ddic

def solve(N, K, A):
    dp = [0] * N
    dp[0] = 1
    windows = [0] * K
    for i in xrange(1, N):
        for k, (L, R) in enumerate(A):
            if 0 <= i - L < N:
                windows[k] += dp[i - L]
            if 0 <= i - R - 1 < N:
                windows[k] -= dp[i - R - 1]
            windows[k] %= MOD
        dp[i] += sum(windows)
        dp[i] %= MOD

    return dp[-1] % MOD
    
N, K = rrm()
A = rrmm(K)
print solve(N, K, A) % MOD
