N, K = map(int,input().split())
LR = [tuple(map(int,input().split())) for _ in range(K)]
d = [0]*N
ans = [0]*N
ans[0] = 1
MOD = 998244353
for i in range(N):
    x = ans[i]
    for k in range(K):
        L, R = LR[k]
        if i+L < len(d):
            d[i+L] += x
            d[i+L] %= MOD
        if i+R+1 < len(d):
            d[i+R+1] -= x
            d[i+R+1] %= MOD
    for j in range(i+2, len(d)):
        d[j] += d[j-1]
        d[j] %= MOD
    for j in range(len(d)):
        ans[j] = (ans[j]+d[j]) % MOD
        d[j] = 0
print(ans[-1] % MOD)