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

MOD = 998244353

interval = []
for i in range(K):
    L,R = map(int,input().split())
    for j in range(L,R+1):
        interval.append(j)

dp = [0]*N
dp[0] = 1

for i in range(N-1):
    for j in interval:
        if j <= N-1 - i:
            dp[i+j] += dp[i]
            dp[i+j] %= MOD

print(dp[N-1])