#!/usr/bin/env python3

def main():
    n, k = map(int, input().split())
    mod = 998244353
    s = []
    for i in range(k):
        l, r = map(int, input().split())
        s += range(l, r + 1)
    s.sort()
    dp = [0] * n
    dp[0] = 1
    for i in range(n):
        if dp[i] == 0:
            continue
        for d in s:
            if i + d < n:
                dp[i + d] += max(dp[i], 1)
                dp[i + d] %= mod
            else:
                break
    print(dp[n - 1])


if __name__ == "__main__":
    main()
