This page is still under construction.

Parts of this page are still being built. What you see may change.

Hyperactive Boy Gangsan

Time limit1sMemory limit128 MB

Summary
Count minimal subsets of intervals that cover [0, M] with no redundant interval, modulo 10^8, over multiple test cases.
Level

Medium7 of 10

Topics
Dynamic programming, Intervals, Combinatorics, Sorting
Solved
No attempts yet

Problem

Gangsan loves being active so much that if he rests for even a single instant during the day, thorns sprout all over his body and he suffers. Having lived like this for 24 years, he has gained the ability to work on any number of tasks at the same time.

A day starts at time 00 and ends at time MM, and every instant of the day is a real number between 00 and MM inclusive. Gangsan has a list of tasks he can do today; each task has a start time SS and an end time FF. If he picks a task, he is fully active from time SS to time FF inclusive (both endpoints included).

Gangsan wants to save his tasks, so he will only pick a minimal subset that satisfies both of the following conditions.

  1. At every instant of the day he is doing at least one task. In other words, the chosen tasks' intervals cover the whole of [0,M][0, M].
  2. Removing any single one of the chosen tasks always creates an instant during the day at which he is doing nothing. In other words, no chosen task is redundant.

Within a minimal subset, several tasks may be running at the same instant.

Given the list of tasks Gangsan can do today, count the number of distinct minimal subsets.

Input

The input consists of several test cases.

The first line of each test case contains the day's end time MM and the number of available tasks NN. (1≤M≤1091 \le M \le 10^9, 1≤N≤1001 \le N \le 100)

Each of the next NN lines contains a task's start time SS and end time FF. (0≤S<F≤M0 \le S < F \le M)

The input ends with a line containing two integers 00 00, which must not be processed.

Output

For each test case, print the number of minimal subsets modulo 10810^8, one per line.

Examples1

  1. Example 1

    Input
    8 7
    0 3
    2 5
    5 8
    1 3
    3 6
    4 6
    0 2
    1 1
    0 1
    2 1
    0 1
    0 0
    
    Expected output
    4
    1
    0