import numpy as np
from numba import jit
     
MOD = 998244353
N, K = list(map(int, input().split()))
     
dp = np.zeros(N+1, dtype=np.int64)
mv = np.zeros(N+1, dtype=np.int64)
for i in range(K):
    l, r = list(map(int, input().split()))
    for j in range(l, r+1):
        mv[j] = 1

@jit(nopython=True)
def shift_and_add(dp, mv, i):
    for i in range(1, N+1):
        dp += np.concatenate((np.zeros(i+1, dtype=np.int64), mv[1:N-i+1]*dp[i]))
        dp %= MOD
            
dp[1] = 1
shift_and_add(dp, mv, i)
     
print(dp[N])
