Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(using C++, using vector for this problem please) Big Segment time limit per test 2 seconds memory limit per test 256 megabytes A coordinate line

(using C++, using vector for this problem please)

Big Segment

time limit per test 2 seconds

memory limit per test 256 megabytes

A coordinate line has n segments, the i-th segment starts at the position li and ends at the position ri. We will denote such a segment as [li,ri].

You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.

Formally we will assume that segment [a,b] covers segment [c,d], if they meet this condition acdb.

Input

The first line contains integer n (1n105) the number of segments. Next n lines contain the descriptions of the segments. The i-th line contains two space-separated integers li,ri (1liri109) the borders of the i-th segment. It is guaranteed that no two segments coincide.

Output

Print a single integer the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input.

Examples

input

3

1 1

2 2

3 3

output

-1

input

6

1 5

2 3

1 10

7 10

7 7

10 10

output

3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions