n,k=map(int,input().split())
k_list=[]

for i in range(k):
    l,r=map(int,input().split())
    k_list.append([l,r])

dp=[0]*n
dp[0]=1
dpsum=[0]*n
dpsum[0]=1

for i in range(1,n):
    for j in range(k):
        l,r=k_list[j]
        li=i-r
        ri=i-l
        if ri<0:
            continue
        if li<=0:
            dp[i]+=dpsum[ri]
        else:
            dp[i]+=dpsum[ri]-dpsum[li-1]
    dpsum[i]=dpsum[i-1]+dp[i]

print(dp[n-1]%998244353)
