import numpy as np
N,K = map(int, input().split())
L = list()
R = list()
for _ in range(K):
    a,b = map(int, input().split())
    for _1 in range(_):
        x,y = L[_1],R[_1]
        if x <= a <= y or x <= b <= y :
            L[_1] = min(a,x)
            R[_1] = max(b,y)
            break
    else:
        L.append(a)
        R.append(b)
sep = len(L)


MOD = 998244353
dp = np.zeros(N+10,dtype=np.int64)
dp[1] = 1
for i in range(1,N+1):
    for l, r in zip(L,R):
        dp[min(N + 1, i + l):min(N + 1, i + r + 1)] += dp[i]
        # print(dp)

print(dp[N]%MOD)


