N, K = map(int, input().split())

L = [0]*K
R = [0]*K

for i in range(K):
    L[i], R[i] = map(int, input().split())

L = sorted(L)
R = sorted(R)

mod = 998244353

def c(n):
    if n < 1:
        return 0
    elif n == 1:
        return 1
    else:
        ans = 0
        for i in range(K):
            for j in range(L[i],R[i]+1):
                if n-j < 1:
                    return ans
                ans += c(n-j) % mod
        return ans % mod

print(c(N) % mod)