from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
import numpy as np
setrecursionlimit(10 ** 8)

mod = 998244353

def main():
    from builtins import int, map
    N, K = map(int, input().split())
    LR = [tuple(map(int, input().split())) for _ in range(K)]
    # LR = sorted(LR, key = lambda x: x[1], reverse=True)
    # print(N, K, LR)
    
    possible = np.zeros(N + 1, dtype=np.int)
    possible[1] = 1
    for k in range(1, N + 1):
        if possible[k] > 0:
            for (l, r) in LR:
                if k + l > N:
                    continue
                possible[k+l:k+r+1] += possible[k]
                possible[k+l:k+r+1] %= mod
    ans = possible[N] % mod
    print(ans)

if __name__ == '__main__':
    main()
