In a certain city, the houses on one side of the only street are numbered consecutively from to . The distance between neighboring houses is significant, so residents usually travel by shuttle taxis. There are shuttle taxis, each operating on its own route.
A trip by any taxi costs exactly one dollar, regardless of the distance traveled, but each taxi can stop only at specific houses, at least two per route. The stops for a route are specified by two numbers: and . Here, is the smallest house number where the taxi stops, and is the period between stops.
For example, a shuttle taxi with parameters and for N=11 will stop at houses , , , , , , , and so on, so some houses may have no taxi stopping at them.
Given , , and the parameters for all routes, determine:
The number of houses where no taxi stops.
The minimum number of dollars required to travel from the first house to the -th house, or output if it is impossible.
All numbers , , , and are natural numbers, with constraints 1 \le N \le 200, 1 \le A,B,M \le 20.
The first line contains two numbers: and .
Each of the following lines contains two numbers and — the parameters for each shuttle taxi route.
Output two numbers:
The number of houses where no taxi stops.
The minimum number of dollars required to travel from the first house to the -th house, or if it is impossible.
Example 1