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())
        aa.append([l,r])
    kk[0]=1
    for i in range(n+1):
        for a in aa:
            for j in range(a[0],a[1]+1):
                if i+j<=n:
                    kk[i+j]+=kk[i]
                    kk[i+j]%=ww

    print(kk[n])
resolve()