def main():
    n, k = map(int, input().split())
    memo = [-1] * (n+1)
    s = []

    def calc(n):
        if memo[n]>=0:
            return memo[n]
        c = 0
        for v in s:
            if v>n:
                break
            if v==n:
                c += 1
            else:
                c += calc(n-v)
        # print(n, c)
        memo[n] = c % 998244353
        return c

    for _ in range(k):
        l, r = map(int, input().split())
        s.extend(range(l, r+1))
    s.sort()

    ans = calc(n-1) % 998244353
    print(ans)
    # print(memo)

main()