N,K = map(int,input().split())
S = []
for i in range(K):
    L,R = map(int,input().split())
    for j in range(L,R+1):
        S.append(j)
def countWays(arr, m, N):
    count = [0 for i in range(N + 1)]
    count[0] = 1
    for i in range(1, N + 1):
        for j in range(m):
            if (i >= arr[j]):
                count[i] += count[i - arr[j]]
    return count[N]
print(countWays(S,len(S),N-1)%998244353)