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

import sys


def std_in():
    return sys.stdin.readline().strip()


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


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()
    print(s)
    d = dict()
    d[1] = 1
    ans, d = find(n, s, d)
    print(ans % 998244353)


def find(n, s, d):
    ans = 0
    for ss in s:
        if n - ss <= 0:
            d[n - ss] = 0
        if not n - ss in d.keys():
            d[n - ss], d = find(n - ss, s, d)
        ans += d[n - ss]
    return ans, d


if __name__ == "__main__":
    main()
