
def main():
    N, K = map(int,input().split())

    mod = 998244353

    S = []
    for _ in range (K):
        l,r = map(int,input().split())
        for i in range (l,r+1):
            S.append(i)

    S.sort()

    ans = [0]*N
    ans[0] = 1

    for i in range (1,N):
        for j in S:
            if i-j < 0:
                break
            else:
                ans[i] += ans[i-j]
        ans[i] %= mod


    print(ans[N-1])


main()
