#!/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()
    s = set(s)
    d = dict()
    d[1] = 1

    n_list = [n]
    for nn in n_list:
        for ss in s:
            if nn-ss > 0:
                if nn-ss not in n_list:
                    n_list.append(nn-ss)

    n_list = sorted(n_list)
    for i in n_list:
        if i == 1:
            continue
        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()
