mod = 998244353


def solve():
    N, K = map(int, input().split())
    S = []
    for _ in range(K):
        l, r = map(int, input().split())
        S += list(range(l, r+1))
    S.sort()
    dp = [0] * N
    dp[0] = 1
    for i in range(N-1):
        for s in S:
            if i + s > N-1:
                break
            dp[i+s] = (dp[i+s] + dp[i]) % mod
    print(dp[-1])


if __name__ == '__main__':
    solve()