mod = 998244353
n,k = map(int,input().split())
s = [list(map(int,input().split())) for i in range(k)]
c = [0]*(n+1)
c[0] = 1
for i in range(n):
    for j,k in s:
        if i+j<n+1:
            c[i+j] += c[i]
        if i+k<n:
            c[i+k+1] -= c[i]
    if i>0:
        c[i+1] += c[i] 
        c[i+1] %= mod

print(c[n-1])