def resolve():
    n, k = map(int, input().split())
    n-=1
    ww=998244353
    aa=[]
    kk=[0]*(n+1)
    for _ in range(k):
        l, r = map(int, input().split())
        for i in range(l,r+1):
            aa.append(i)
    kk[0]=1
    for i in range(n+1):
        for a in aa:
            if i+a<=n:
                kk[i+a]+=kk[i]
                kk[i+a]%=ww

    print(kk[n])
resolve()