N, K = map(int, input().split())
d = [0]*(N+1)
l = []
for i in range(K):
    l.append(list(map(int, input().split())))
di = []
for i in range(K):
    a, b = l[i][0], l[i][1]
    for j in range(b-a+1):
        di.append(a+j)


adj = {}
for i in range(N-1):
    lis = [i+1+j for j in di if i+1+j<=N]
    adj[i+1] = lis

ans = [0]*(N+1)
ans[1] = 1
for i in range(N-1):
    #i+1番目
    for x in adj[i+1]:
        ans[x] = ans[x] + ans[i+1]
        if(ans[x]>998244353):
            ans[x] = ans[x]%998244353
print (ans[-1]%998244353)