Dexter is playing again with N substances trying to complete his greatest invention. Because it's running late, Dexter has decided the invention will have to wait until tomorrow. In the meanwhile, he needs to find a way to store the N substances in his two fridges. Each fridge can be set to a certain temperature, an integer value between −100 and 100. For each of the N substances, Dexter knows an interval [ai,bi], meaning the storing temperature of the i-th substance needs to fall in that specific interval.
Help Dexter decide the temperatures of the two fridges.
The first line contains a single integer N.
Each of the following N lines contains two values ai and bi, representing the storing interval for the i-th substance.
If there is no solution, print −1.
Otherwise, print two values T1 and T2 (T1≤T2), representing the temperatures of the two fridges.
Input | Output | Explanation |
---|---|---|
2 10 12 20 24 | 10 20 | Each substance will be stored in a separate fridge. |
4 -54 -40 -50 -42 36 77 49 100 | -50 49 | The first two substances will be stored in the first fridge, while the last two substances will be stored in the second fridge. |