LCC '21 Contest 3 J4 - A Chemistry Problem

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

After finishing his chemistry lab early, David is experimenting with a mysterious solution that his teacher gave him.

In particular, David wants to find the number of hydronium ions in the solution, which he knows to be a positive integer. To do so, he has asked his teacher for N acid-base indicators to test the solution with. While conducting the experiments, the ith indicator tells David with certainty that the number is between L_i and R_i, inclusive.

David would like you to figure out the minimum and maximum possible number of hydronium ions the solution can have, or that no number works because someone has mislabeled the indicators.

Input Specifications

The first line will contain an integer, N (1 \le N \le 10 ^ 5).

The next N lines will each contain two space-separated integers, L_i and R_i (1 \le L_i \le R_i \le 10 ^ 9).

Output Specifications

Output one line containing two space-separated integers, the minimum and maximum possible number of hydronium ions the solution can have. If there are no possible numbers, output -1 instead.

Sample Input

2
1 6
2 6

Sample Output

2 6

Comments

There are no comments at the moment.