import sys
sys.setrecursionlimit(10**6)

MOD = 998244353


def main(input, print):
    n, k = map(int, input().split())
    s = []
    for i in range(k):
        l, r = map(int, input().split())
        for j in range(l, r+1):
            s.append(j)
    s = list(set(s))
    s.sort()
    dp = [0]*(n+1)
    dp[1] = 1
    for i in range(1, n+1):
        for m in s:
            ni = i+m
            if ni > n:
                continue
            dp[ni] += dp[i]
            dp[ni] %= MOD
    print(dp[n])


if __name__ == '__main__':
    main(sys.stdin.readline, print)
