#!/usr/bin/env python3
import sys

def main():
    input = sys.stdin.readline
    n, k = map(int, input().split())
    tmp = []
    for _ in range(k):
        l, r = map(int, input().split())
        for i in range(l, r + 1):
            tmp.append(i)
    tmp.sort()
    dp = [0] * n
    dp[0] = 1

    for i in range(n):
        for j in range(len(tmp)):
            if i + tmp[j] <= n - 1:
                dp[i + tmp[j]] += dp[i]
                dp[i + tmp[j]] %= 998244353
            else:
                del tmp[j:]
    print(dp[-1])


if __name__ == '__main__':
    main()
