Today is International Mathematics Day! And "true analysis" is one of his exciting and…
- User
Today is International Mathematics Day! And "true analysis" is one of his exciting and lovely topics...
Image Description%align_center_start%
Dr. Maryam Mirzakhani
%align_end%
The meaning of the interval [ a , b ] [a,b] (read closed interval a a and b b) It means the set of all points between a a and b b (incl a a and b b) In other words, it means:
[ a , b ]
x ∈ R ∣ a ≤ x ≤ b [a,b]=x∈R∣a≤x≤b
The meaning of the interval ( a , b ) (a,b) (read open interval a a and b b) Set of all points between a a and b b (without a a and b b) In other words, it means:
( a , b )
x ∈ R ∣ a < x < b (a,b)=x∈R∣a<x<b
Mohsen of all closed interval real numbers [ 1 , 100 ] noted [1,100].
Mohsen n n intervals [ l i , r i ] [l i R i ] that ( 1 ≤ l i ≤ r i ≤ 100 , 1≤l i ≤r i ≤100,) in the set of numbers he likes and if a number is removed from it, Mohsen gets upset. Note that these ranges may be shared.
In each operation, Mohsen can open an interval like ( x , y ) (x,y) that ( 1 ≤ x < y ≤ 100 1≤x<y≤100) and all the remaining points of the optimal set that are in this interval; Remove from Mohsen's collection.
Mohsen wants to do something with the least number of operations so that only Mohsen's favorite intervals remain in his set. (Read the examples to better understand the question.)
Help Mohsen calculate the minimum number of necessary operations. If it is not possible to do this with a finite number of operations, tell this bad news to Mohsen.
input In the first line, enter a positive integer n n is given to indicate the number of intervals. 1 ≤ n ≤ 100 1≤n≤100 in n n The next line in the line i i two integers l i l i and r i r i has come 1 ≤ l i ≤ r i ≤ 100 1≤l i ≤r i ≤100
output If this is possible by performing the above operations, print the minimum number of necessary operations. otherwise print -1.
examples Sample entry 1 5 1 30 90 100 10 60 75 75 70 80 Plain text Sample output 1 2 Plain text Enough time ( 60 , 70 ) (60,70) and interval ( 80 , 90 ) (80,90) should be deleted.
Description of the image
Sample input 2 1 1 100 Plain text Sample output 2 0 Plain text No need to remove any spaces.
Description of the image
Sample entry 3 1 2 99 Plain text Sample output 3 -1 Plain text Ignore favorite intervals just the interval [ 1 , 2 ) [1,2) and interval ( 99 , 100 ] (99,100) remains that these two intervals cannot be covered with a finite number of intervals. c++
- Assistant