#!/usr/bin/env python3
import sys

def main():
    input = sys.stdin.readline
    n, k = map(int, input().split())
    tmp = set()
    for _ in range(k):
        l, r = map(int, input().split())
        for i in range(l, r + 1):
            tmp.add(i)
    dp = [0] * n
    dp[0] = 1
    for i in range(n):
        for j in tmp:
            if i + j <= n - 1:
                dp[i + j] += dp[i]
                dp[i + j] %= 998244353
    
    print(dp[-1])


if __name__ == '__main__':
    main()
