#!/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
    tmp_len = len(tmp)

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


if __name__ == '__main__':
    main()
