N, K = map(int, input().split())
MOD = 998244353
D = []
for _ in range(K):
    l, r = map(int, input().split())
    D.append((l,r))
imos = [0]*(N+2)
dp = [0]*(N+1)
imos[0]=1
imos[1]=-1
for i in range(N):
    dp[i] = dp[i-1] + imos[i]
    dp[i] %= MOD
    for a, b in D:
        imos[min(i+a,N+1)] += dp[i]
        imos[min(i+b+1,N+1)] -= dp[i]

print(dp[N-1])