import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines

def main():
    large_num = 998244353
    n, k = map(int, input().split())
    n -= 1
    s = set()
    m = map(int, read().split())
    ab = zip(m, m)
    for a, b in ab:
        for i1 in range(a, b + 1):
            s.add(i1)
    dp = [0] * (n + 1)
    dp[0]=1
    s = list(s)
    s.sort()
    s = tuple(s)
    for i1 in range(1, n+1):
        for se in s:
            if se > i1:
                break
            else:
                dp[i1] += dp[i1 - se]
        dp[i1] = dp[i1] % large_num
    print(dp[-1])

if __name__ == '__main__':
    main()

