def main():
    n,k=map(int,input().split())
    xy = [map(int, input().split()) for _ in range(k)]
    x, y = [list(i) for i in zip(*xy)]
    slist=[]
    for j in range(k):
        jlist=list(range(x[j],y[j]+1))
        slist.extend(jlist)
    alist=[1]
    blist=[0]*(n-1)
    alist.extend(blist)
    for r in range(n):
        for sa in slist:
            if r+sa<=n-1:
                alist[r+sa]=(alist[r]+alist[r+sa])%998244353
    ans=alist[n-1]
    answer=ans%998244353
    print(answer)


main()