#ABC179-d
import sys,math,collections,itertools
input = sys.stdin.readline
m=998244353

N,K=list(map(int,input().split()))
DP = [0]*(2*10**5+1)
move = []
for _ in range(K):
    l,r=list(map(int,input().split()))
    move += list(range(l,r+1))

ans = 0
for i in range(2,N+1):
    for mo in move:
        if i-mo<=0:
            break
        elif i-mo==1:
            DP[i]+=1
        else:
            DP[i]+= DP[i-mo]
print(DP[N]%m)
        