#C6442. Minimum Number of Aircraft Required

    ID: 50203 Type: Default 1000ms 256MiB

Minimum Number of Aircraft Required

Minimum Number of Aircraft Required

You are given several datasets, each representing a list of scheduled flights. Each flight is defined by a departure time and an arrival time. An aircraft can be used for a new flight if its previous flight’s arrival time is less than or equal to the new flight’s departure time. Your task is to determine the minimum number of aircraft needed to cover all the flights for each dataset.

Note: The input terminates when a dataset starting with "0 0" is encountered. This terminating dataset should not be processed.

The problem can be solved using a greedy approach with a min-heap data structure.

inputFormat

The input is provided via standard input (stdin) and consists of multiple datasets. Each dataset starts with a line containing two integers N and F, where N is the number of scheduled flights (for descriptive purposes) and F is the number of flights that follow. The next F lines each contain two integers representing the departure and arrival times of a flight. A line containing "0 0" marks the end of the input and should not be processed.

outputFormat

For each dataset (except the terminating one), output a single integer on a separate line representing the minimum number of aircraft required so that all flights can be covered.

## sample
3 3
480 600
610 720
300 360
3 4
0 200
200 400
400 600
600 800
0 0
1

1

</p>