#!/usr/bin/python
# -*- coding: UTF-8 -*-


def main():
    n, m = map(int, input().split())
    p = [list(map(int, input().split())) for _ in range(m)]
    s = set()
    for pp in p:
        s |= set(range(pp[0], pp[1]+1))
    s = list(s)
    s.sort()
    d = dict()
    d[1] = 1
    for i in range(2, n+1):
        ans = 0
        for ss in s:
            if i-ss > 0:
                ans += d[i - ss]
        d[i] = ans
    print(d[n] % 998244353)


if __name__ == "__main__":
    main()
