N, K = map(int, input().split())
mod = 998244353
lr = [list(map(int, input().split())) for _ in range(K)]

dp = [0]*(N+1)
tmp = 1
imos = [0]*(N+1)
imos[0] = 0

for i in range(N):
    imos[i] += dp[i]
    if i != 0:
        tmp = imos[i]+tmp
    for k in range(K):
        l, r = lr[k]
        if l+i > N: continue
        dp[l+i] = (dp[l+i]+tmp)%mod
        dp[min(N, r+i+1)] = (dp[min(N, r+i+1)]-tmp)%mod
print(imos[N-1]%mod)