def solve(S,N):
    mod = 998244353
    DP = [0 for _ in range(N+1)]
    DP[1] = 1
    for i in range(2,N+1):
        for j in range(len(S)):
            if i - S[j] >= 1:
                DP[i] += DP[i-S[j]]
                DP[i] %= mod

    return DP[N]

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

    S.sort()
    print(solve(S,N))

if __name__ == "__main__":
    main()
