You are given a sequence a_1, a_2, ..., a_{n} of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment a_{i} lies within segment a_{j}.

Segment [l_1, r_1] lies within segment [l_2, r_2] iff l_1 ≥ l_2 and r_1 ≤ r_2.

Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.


-----Input-----

The first line contains one integer n (1 ≤ n ≤ 3·10^5) — the number of segments.

Each of the next n lines contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 10^9) — the i-th segment.


-----Output-----

Print two distinct indices i and j such that segment a_{i} lies within segment a_{j}. If there are multiple answers, print any of them. If no answer exists, print -1 -1.


-----Examples-----
Input
5
1 10
2 9
3 9
2 3
2 9

Output
2 1

Input
3
1 5
2 6
6 20

Output
-1 -1



-----Note-----

In the first example the following pairs are considered correct:  (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;  (3, 2), (4, 2), (3, 5), (4, 5) — touch one border;  (5, 2), (2, 5) — match exactly.

Difficulty: MEDIUM
Tags: Sorting

Implementation

Greedy algorithms
Skill types: Sorting

Greedy algorithms
Expected Time Complexity: O(NLOG(N))

Starter code:

Solutions:
from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
import math

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def divs(n, start=2):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors
import sys
inf = float('inf')
mod = 1000000007

def array():
	return list(map(int, sys.stdin.readline().split()))

def intt():
	return map(int, sys.stdin.readline().split())
from bisect import bisect_left
import sys
n = int(sys.stdin.readline())
ls = []
for i in range(n):
	(u, v) = map(int, sys.stdin.readline().split())
	ls.append((u, v, i))
ls.sort(key=lambda x: (x[0], -1 * x[1]))
max_r = ls[0][1]
ind = ls[0][2]
for i in range(1, n):
	if ls[i][1] <= max_r:
		print(ls[i][2] + 1, ind + 1)
		exit()
	if ls[i][1] > max_r:
		max_r = ls[i][1]
		ind = ls[i][2]
print(-1, -1)


n = int(input())
S = []
for i in range(n):
	(l, r) = map(int, input().split())
	S.append([l, r, i + 1])
S.sort(key=lambda x: (x[1], -x[0]))
for i in range(n - 1):
	(l2, r2, j2) = S[i]
	(l1, r1, j1) = S[i + 1]
	if l1 <= l2 and r1 >= r2:
		print(j2, j1)
		exit(0)
print(-1, -1)


n = int(input())
sections = sorted((tuple(map(int, [i + 1] + input().split())) for i in range(n)), key=lambda x: (x[1], -x[2]))
max_end = (sections[0][0], sections[0][2])
for s in sections[1:]:
	if s[2] <= max_end[1]:
		print('{} {}'.format(s[0], max_end[0]))
		break
	else:
		max_end = (s[0], s[2])
else:
	print('-1 -1')


def readline():
	return tuple(map(int, input().split()))

def readlines(count):
	return (readline() for __ in range(count))

def main():
	(n,) = readline()
	segments = sorted((readline() + (idx + 1,) for idx in range(n)))
	prev = (-1, -1, -1)
	for segment in segments:
		assert prev[0] <= segment[0]
		if prev[0] == segment[0]:
			assert prev[1] <= segment[1]
			print(prev[2], segment[2])
			break
		elif prev[1] >= segment[1]:
			print(segment[2], prev[2])
			break
		prev = segment
	else:
		print(-1, -1)
main()


n = int(input())
a = []
for i in range(n):
	(l, r) = map(int, input().split())
	a.append([l, r, i + 1])
a.sort(key=lambda f: (f[0], -f[1]))
large = 0
for i in range(1, n):
	if a[i][1] <= a[large][1]:
		print(str(a[i][2]) + ' ' + str(a[large][2]))
		exit()
	else:
		large = i
print('-1 -1')


while True:
	try:

		def solution(n):
			seg = []
			for i in range(n):
				(l, r) = map(int, input().split())
				mn = min(l, r)
				mx = max(l, r)
				seg.append([mn, mx, i])
			seg.sort()
			res = [seg[0][0], seg[0][1], seg[0][2]]
			for i in range(1, n, 1):
				if seg[i][1] <= res[1]:
					res.append(seg[i][2])
					break
				elif seg[i][0] == res[0]:
					res.insert(2, seg[i][2])
					break
				else:
					res[0] = seg[i][0]
					res[1] = seg[i][1]
					res[2] = seg[i][2]
			if len(res) == 4:
				print(res[3] + 1, res[2] + 1)
			else:
				print('-1 -1')

		def read():
			n = int(input())
			solution(n)
		if __name__ == '__main__':
			read()
	except EOFError:
		break


n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
for t in range(n):
	a[t].append(t + 1)
a.sort()
for i in range(n - 1):
	if a[i][1] >= a[i + 1][1]:
		print(a[i + 1][2], a[i][2])
		exit(0)
	elif a[i][0] == a[i + 1][0]:
		print(a[i][2], a[i + 1][2])
		exit(0)
print(-1, -1)


import sys
input = sys.stdin.readline
n = int(input())
lista = []
for j in range(n):
	(l, r) = map(int, input().split())
	lista.append([l, r, j + 1])
lista.sort(key=lambda X: (X[0], -X[1], X[2]))
ok = False
for i in range(1, len(lista)):
	if lista[i - 1][0] <= lista[i][0] and lista[i - 1][1] >= lista[i][1]:
		print(lista[i][2], lista[i - 1][2])
		ok = True
		break
if ok == False:
	print(-1, -1)


def main():
	n = int(input())
	seg = []
	for i in range(n):
		(l, r) = map(int, input().split())
		seg.append((l, r, i + 1))
	seg = sorted(seg, key=lambda x: (x[0], -x[1]))
	lar = 0
	sma = -1
	for i in range(1, len(seg)):
		if seg[i][1] <= seg[lar][1]:
			sma = i
			break
		else:
			lar = i
	if sma != -1:
		print(seg[sma][2], seg[lar][2])
	else:
		print(-1, -1)

def __starting_point():
	main()
__starting_point()


from operator import itemgetter
n = int(input())
items = []
for i in range(1, n + 1):
	l = list(map(int, input().split()))
	l.append(i)
	items.append(l)
items = sorted(items, key=itemgetter(0, 1))

def find(n, items):
	for i in range(n):
		for j in range(i + 1, n):
			if items[i][0] <= items[j][0] and items[i][1] >= items[j][1]:
				return (items[j][2], items[i][2])
			if items[i][0] >= items[j][0] and items[i][1] <= items[j][1]:
				return (items[i][2], items[j][2])
			if items[j][1] > items[i][1] or items[j][0] > items[i][1]:
				break
	return (-1, -1)
print(*find(n, items))


import sys
input = sys.stdin.readline
n = int(input())
ls = []
for i in range(n):
	(l, r) = list(map(int, input().strip().split()))
	ls.append([l, r, i])
ls = sorted(ls, key=lambda x: (x[0], -x[1]))
flag = False
mmax = -1
arg_mother = 0
for i in range(n):
	(cur_l, cur_r, child) = ls[i]
	if cur_r <= mmax:
		print(child + 1, arg_mother + 1)
		flag = True
		break
	else:
		mmax = cur_r
		arg_mother = ls[i][2]
if not flag:
	print(-1, -1)


n = int(input())
pairs = [list(map(int, input().split())) + [i] for i in range(n)]
pairs.sort(key=lambda x: (x[0], -x[1]))
for i in range(1, n):
	if pairs[i][1] <= pairs[i - 1][1]:
		print(pairs[i][2] + 1, pairs[i - 1][2] + 1)
		break
else:
	print(-1, -1)


n = int(input())
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append((x, y, i + 1))
a.sort(key=lambda aa: (aa[0], -aa[1]))
m = 0
for i in range(1, n):
	if a[i][1] > a[m][1]:
		m = i
	else:
		print('%i %i' % (a[i][2], a[m][2]))
		exit()
print('-1 -1')


import sys
R = lambda : map(int, sys.stdin.buffer.readline().split())
n = list(R())[0]
a = []
for i in range(n):
	(x, y) = R()
	a.append((x, -y, i + 1))
a.sort()
ans = (-1, -1)
for x in range(1, len(a)):
	if a[x][1] >= a[x - 1][1]:
		ans = (a[x][2], a[x - 1][2])
		break
print(*ans)


import sys
input = sys.stdin.readline
n = int(input())
lr = [(i,) + tuple(map(int, input().split())) for i in range(n)]
lr.sort(key=lambda k: (k[1], -k[2]))
for i in range(n - 1):
	if lr[i + 1][2] <= lr[i][2]:
		print(lr[i + 1][0] + 1, lr[i][0] + 1)
		exit()
print(-1, -1)


from sys import stdin
n = int(stdin.readline())
r = 1
arr = []
for i in range(n):
	(x, y) = map(int, stdin.readline().split())
	arr.append((x, -y, r))
	r += 1
la = sorted(arr, key=lambda x: (x[0], x[1]))
for i in range(1, n):
	if la[i - 1][1] <= la[i][1]:
		print(la[i][2], la[i - 1][2])
		exit()
print(-1, -1)


def res(d, N):
	for i in range(1, N):
		if d[i][1] <= d[i - 1][1]:
			return str(d[i][2] + 1) + ' ' + str(d[i - 1][2] + 1)
	return '-1 -1'
N = int(input())
d = []
for i in range(N):
	(a, b) = list(map(int, input().split()))
	d.append((a, b, i))
d = sorted(d, key=lambda x: (x[0], -x[1]))
print(res(d, N))


from operator import itemgetter

def cmpnr(a, b):
	if a[0] < b[0]:
		return True
	if a[0] > b[0]:
		return False
	return a[1] > b[1]
n = int(input())
seg = []
for i in range(n):
	(a, b) = map(int, input().split())
	seg.append((a, b, i + 1))
seg = sorted(seg, key=lambda t: (t[0], -t[1]))
maxr = 0
maxri = 0
for (a, b, i) in seg:
	if b <= maxr:
		print(i, maxri)
		exit()
	if b > maxri:
		maxr = b
		maxri = i
print(-1, -1)


R = lambda : map(int, input().split())
n = int(input())
A = []
for i in range(n):
	(a, b) = R()
	A.append((a, -b, i + 1))
A = sorted(A)
for i in range(1, n):
	if A[i][1] >= A[i - 1][1]:
		print(A[i][2], A[i - 1][2])
		break
else:
	print(-1, -1)


import sys
read = lambda : map(int, sys.stdin.buffer.readline().split())
n = list(read())[0]
s = []
for i in range(n):
	(l, r) = read()
	s.append((l, -r, i + 1))
s.sort()
ans = (-1, -1)
for i in range(1, n):
	if s[i][1] >= s[i - 1][1]:
		ans = (s[i][2], s[i - 1][2])
		break
print(*ans)


n = int(input())
a = []
for i in range(n):
	x = list(map(int, input().split()))
	a.append(x)
b = a.copy()
if n == 1:
	print(-1, -1)
	exit()
a.sort()
for j in range(1, n):
	if a[j][0] >= a[j - 1][0] and a[j][1] <= a[j - 1][1] or (a[j][0] == a[j - 1][0] and a[j][1] >= a[j - 1][1]):
		if a[j][0] == a[j - 1][0] and a[j][1] == a[j - 1][1]:
			print(b.index(a[j]) + 1, n - b[::-1].index(a[j - 1]))
		elif a[j][0] == a[j - 1][0] and a[j][1] > a[j - 1][1]:
			print(b.index(a[j - 1]) + 1, b.index(a[j]) + 1)
		else:
			print(b.index(a[j]) + 1, b.index(a[j - 1]) + 1)
		exit()
print(-1, -1)


def f(n, segments):
	segments.sort(key=lambda tup: tup[1], reverse=True)
	segments.sort(key=lambda tup: tup[0])
	for i in range(n - 1):
		if segments[i][1] >= segments[i + 1][1]:
			return '{} {}'.format(segments[i + 1][2], segments[i][2])
	return '-1 -1'
n = int(input())
segments = []
for i in range(n):
	seg = [int(i) for i in input().split()]
	seg.append(i + 1)
	segments.append(seg)
print(f(n, segments))


n = int(input())
a = sorted(((l, -r, i) for (i, (l, r)) in enumerate((map(int, input().split()) for _ in [0] * n), 1)))
print(*next(((y[2], x[2]) for (x, y) in zip(a, a[1:]) if x[1] <= y[1]), (-1, -1)))


a = []
n = int(input())
for i in range(n):
	(l, r) = map(int, input().split())
	a.append([l, r, i + 1])
a.sort(key=lambda x: (x[0], -x[1]))
r = 0
iid = 0
f = 1
for i in range(n):
	if r >= a[i][1]:
		f = 0
		print(a[i][2], a[iid][2])
		break
	else:
		r = a[i][1]
		iid = i
if f:
	print('-1 -1')


from sys import stdin
n = int(input())
seg = []
inp = stdin.readlines()
for i in range(n):
	(l, r) = map(int, inp[i].split())
	seg.append([l, r, i + 1])
seg.sort(key=lambda x: x[1], reverse=True)
seg.sort(key=lambda x: x[0])
if n == 1:
	print(-1, -1)
else:
	ans = [-1, -1]
	for i in range(1, n):
		(l1, r1) = seg[i - 1][:2]
		(l2, r2) = seg[i][:2]
		if l2 >= l1 and r2 <= r1:
			ans = [seg[i][2], seg[i - 1][2]]
			break
	print(*ans)


import sys
import math
import bisect
import itertools
n = int(sys.stdin.readline().strip())

def lies(l1, r1, l2, r2):
	return l1 >= l2 and r1 <= r2
segs = []
for n0 in range(n):
	(l, r) = map(int, sys.stdin.readline().strip().split(' '))
	segs.append((l, r, n0))
segs = sorted(segs)
if n == 1:
	print('-1 -1')
else:
	for n0 in range(n):
		(l1, r1, i) = segs[n0]
		if n0 == 0:
			(l2, r2, j) = segs[n0 + 1]
			if lies(l1, r1, l2, r2):
				print(i + 1, j + 1)
				break
		elif n0 == n - 1:
			(l2, r2, j) = segs[n0 - 1]
			if lies(l1, r1, l2, r2):
				print(i + 1, j + 1)
				break
		else:
			(l2, r2, j) = segs[n0 - 1]
			if lies(l1, r1, l2, r2):
				print(i + 1, j + 1)
				break
			(l2, r2, j) = segs[n0 + 1]
			if lies(l1, r1, l2, r2):
				print(i + 1, j + 1)
				break
	else:
		print('-1 -1')


n = int(input())
a = []
for i in range(n):
	(l, r) = map(int, input().split())
	a.append((l, r, i))
a = sorted(a, key=lambda x: (x[0], -x[1]))
mr = -1
mi = -1
for i in range(n):
	if a[i][1] <= mr:
		print(a[i][2] + 1, a[mi][2] + 1)
		exit()
	else:
		mr = a[i][1]
		mi = i
print(-1, -1)


n = int(input())
arr = []
for i in range(n):
	(l, r) = map(int, input().split())
	arr.append((l, -r, i))
ans = '-1 -1'
a = sorted(arr)
for i in range(len(a)):
	a[i] = (a[i][0], -a[i][1], a[i][2])
for i in range(len(a) - 1):
	if a[i][0] <= a[i + 1][0] and a[i][1] >= a[i + 1][1]:
		ans = str(a[i + 1][2] + 1) + ' ' + str(a[i][2] + 1)
print(ans)


def solve(a):
	aa = sorted(a)
	maxr = aa[0]
	for ai in aa:
		if ai[2] != maxr[2]:
			if ai[1] <= maxr[1] and ai[0] >= maxr[0]:
				return (ai[2], maxr[2])
			if ai[1] >= maxr[1] and ai[0] <= maxr[0]:
				return (maxr[2], ai[2])
		if ai[1] > maxr[1]:
			maxr = ai
	return (-1, -1)
n = int(input())
a = []
for i in range(n):
	(l, r) = [int(s) for s in input().split()]
	a.append((l, r, i + 1))
(i, j) = solve(a)
print(i, j)


n = int(input())
lst = []
for i in range(n):
	a = list(map(int, input().split()))
	lst.append(a)
l = []
r = []
llst = list(lst)
lst.sort()
for i in range(1, n):
	if lst[i][0] > lst[i - 1][0]:
		if lst[i][1] <= lst[i - 1][1]:
			l = lst[i]
			r = lst[i - 1]
			break
	if lst[i][0] == lst[i - 1][0]:
		if lst[i][1] <= lst[i - 1][1]:
			l = lst[i]
			r = lst[i - 1]
			break
		else:
			l = lst[i - 1]
			r = lst[i]
			break
lind = -1
rind = -1
f = 0
ff = 0
for i in range(n):
	if llst[i] == l and f == 0:
		lind = i + 1
		f = 1
	elif llst[i] == r and ff == 0:
		rind = i + 1
		ff = 1
print(lind, rind)


def main():
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(list(map(int, input().split())) + [i + 1])
	arr.sort(key=lambda x: [x[0], -x[1]])
	ind = 0
	for i in range(1, len(arr)):
		if arr[ind][1] >= arr[i][1]:
			print(arr[i][2], arr[ind][2])
			return
		else:
			ind = i
	print(-1, -1)
main()


n = int(input())
otr = [tuple(map(int, input().split())) for i in range(n)]
left = sorted(otr, key=lambda x: (x[0], -x[1]))
for (i, el) in enumerate(left[1:]):
	(one, two) = (left[i], el)
	if one[0] == two[0] or one[1] >= two[1]:
		print(f'{otr.index(two) + 1} {n - otr[::-1].index(one)}')
		exit()
print(-1, -1)


def solve():
	n = int(input())
	segs = []
	for _ in range(n):
		(s, e) = map(int, input().split())
		segs.append((s, e, _ + 1))
	segs.sort(key=lambda x: (x[0], -x[1]))
	max_right = 0
	big_seg = -1
	for (i, seg) in enumerate(segs):
		if seg[1] <= max_right:
			print(seg[2], segs[big_seg][2])
			return
		else:
			max_right = seg[1]
			big_seg = i
	print(-1, -1)
solve()


def solution():
	n = int(input())
	segments = []
	for (i, _) in enumerate(range(n)):
		(x, y) = input().split(' ')
		segments.append((int(x), int(y), i + 1))
	segments = sorted(segments, key=lambda x: (x[0], -x[1]))
	for (i, seg) in enumerate(segments):
		j = i + 1
		if j >= n:
			print('-1 -1')
			return
		while segments[j][1] <= seg[1]:
			print('{} {}'.format(segments[j][2], seg[2]))
			return
	print('-1 -1')
	return
solution()


import sys
n = int(sys.stdin.buffer.readline().decode('utf-8'))
seg = sorted((list(map(int, line.decode('utf-8').split())) + [i] for (i, line) in enumerate(sys.stdin.buffer)), key=lambda x: (x[0], -x[1]))
(right, j) = (-1, -1)
for (_, r, i) in seg:
	if r <= right:
		print(i + 1, j)
		exit()
	right = r
	j = i + 1
print(-1, -1)


N = int(input())
A = []
for i in range(1, N + 1):
	(l, r) = map(int, input().split())
	A.append([l, r, i])
A.sort(key=lambda x: x[0])
if N == 1:
	print(-1, -1)
	quit()
a = A[0][1]
for i in range(1, N):
	if A[i][0] == A[i - 1][0] and A[i][1] > A[i - 1][1]:
		print(A[i - 1][2], A[i][2])
		quit()
	elif A[i][1] <= a:
		print(A[i][2], A[i - 1][2])
		quit()
	elif i == N - 1:
		print(-1, -1)
		quit()
	else:
		a = A[i][1]


import sys

def inn(a, b):
	return a[0] <= b[0] and b[1] <= a[1]
n = int(input())
seg = []
(a, b) = map(int, input().split())
seg.append((a, b, 1))
for i in range(2, n + 1):
	(a, b) = map(int, input().split())
	seg.append((a, b, i))
seg.sort(key=lambda x: (x[0], -x[1]))
main = seg.pop(0)
for i in seg:
	if inn(main, i):
		print(i[2], main[2])
		return
	if main[1] < i[1]:
		main = i
print(-1, -1)


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print_(x):
	sys.stdout.write(str(x) + ' ')

def rInt():
	return int(input())

def rList():
	arr = input().split()
	return arr

def cInt(arr):
	res = []
	for itr in arr:
		res.append(int(itr))
	return res

def pList(arr):
	for _ in arr:
		print_(_)
test_cases = 1
for test_case in range(test_cases):
	n = rInt()
	rng = []
	for _ in range(n):
		li = rList()
		li = cInt(li)
		li.append(_)
		rng.append(li)
	rng.sort()
	idx1 = idx2 = -1
	mxrht = 0
	idx = 0
	ans = [-1 for i in range(2)]
	for i in range(n):
		lft = rng[i][0]
		rht = rng[i][1]
		mxR = mxrht
		for j in range(i + 1, n):
			if rng[j][0] == rng[i][0]:
				if rng[j][1] > mxR:
					mxR = rng[j][1]
					idx = j
			else:
				break
		if rng[i][1] <= mxR:
			ans[0] = rng[i][2] + 1
			ans[1] = rng[idx][2] + 1
			break
		if rng[i][1] > mxrht:
			mxrht = rng[i][1]
			idx = i
	pList(ans)


from sys import stdin
n = int(stdin.readline().strip())
s = []
for i in range(n):
	(a, b) = map(int, stdin.readline().strip().split())
	s.append((a, -b, i + 1))
s.sort()
a = -1
b = -1
for i in range(n - 1):
	if s[i][0] <= s[i + 1][0] and s[i][1] <= s[i + 1][1]:
		a = s[i][2]
		b = s[i + 1][2]
		break
print(b, a)


n = int(input().strip())
ais = [tuple(map(int, input().strip().split())) for _ in range(n)]

def solve(ais):
	bis = [(l, r, i + 1) for (i, (l, r)) in enumerate(ais)]
	bis.sort(key=lambda t: (t[0], -t[1]))
	rr = bis[0][1] - 1
	ir = bis[0][2]
	for (l, r, i) in bis:
		if r <= rr:
			return (i, ir)
		else:
			rr = r
			ir = i
	return (-1, -1)
(i, j) = solve(ais)
print(i, j)


ai = -1
aj = -1
qtdSeg = int(input())
segs = []
for i in range(qtdSeg):
	(ini, fim) = [int(x) for x in input().split()]
	segs.append((ini, fim, i + 1))
segs.sort(key=lambda x: x[0], reverse=True)
for i in range(len(segs) - 1):
	if segs[i][0] == segs[i + 1][0]:
		if segs[i][1] <= segs[i + 1][1]:
			ai = segs[i][2]
			aj = segs[i + 1][2]
			break
		elif segs[i][1] >= segs[i + 1][1]:
			ai = segs[i + 1][2]
			aj = segs[i][2]
			break
	elif segs[i][1] <= segs[i + 1][1]:
		ai = segs[i][2]
		aj = segs[i + 1][2]
		break
print(ai, aj)


from sys import stdin

class segment:

	def __init__(self, x, y, n):
		self.a = x
		self.b = y
		self.no = n

	def __gt__(self, other):
		if self.a == other.a:
			return self.b < other.b
		return self.a > other.a

	def __lt__(self, other):
		if self.a == other.a:
			return self.b > other.b
		return self.a < other.a

	def __eq__(self, other):
		if self.a == other.a and self.b == self.b:
			return True
		else:
			return False

	def __str__(self):
		return str(self.no)
n = int(stdin.readline())
arr = []
for i in range(n):
	(r, z) = map(int, stdin.readline().split())
	s = segment(r, z, i + 1)
	arr.append(s)
arr.sort()
for i in range(1, n):
	if arr[i].b <= arr[i - 1].b:
		print(arr[i], arr[i - 1])
		exit()
print(-1, -1)


n = int(input())
L = []
for i in range(n):
	L.append(list(map(int, input().split())) + [i + 1])
L.sort(key=lambda X: (X[0], -X[1], X[2]))
X = 0
for i in range(1, n):
	if L[i][1] <= L[i - 1][1]:
		print(L[i][2], L[i - 1][2])
		X = 1
		break
if X == 0:
	print(-1, -1)


from operator import itemgetter
n = int(input())
sList = []
for i in range(n):
	lr = str(input()).split()
	l = int(lr[0])
	r = int(lr[1])
	s = tuple([i, l, r])
	sList.append(s)
f = 0
sList.sort(key=itemgetter(1))
c = sList.pop(0)
for x in sList:
	if x[2] <= c[2]:
		print(str(x[0] + 1) + ' ' + str(c[0] + 1))
		f = 1
		break
	elif x[2] >= c[2] and x[1] == c[1]:
		print(str(c[0] + 1) + ' ' + str(x[0] + 1))
		f = 1
		break
	else:
		c = x
if f == 0:
	print('-1 -1')


n = int(input())
segments = []
for (i, _) in enumerate(range(n)):
	(a, b) = map(int, input().split())
	segments.append(((a, b), i + 1))
segments.sort(key=lambda x: (x[0][0], -x[0][1]))
last_r = 0
last_index = 0
for (segment, index) in segments:
	if last_r >= segment[1]:
		print(index, last_index)
		break
	last_r = segment[1]
	last_index = index
else:
	print(-1, -1)


n = int(input())
d = []
for _ in ' ' * n:
	(x, y) = map(int, input().split())
	d.append([x, -y])
m = a = 0
s = sorted(range(n), key=lambda x: d[x])
for i in s:
	y = d[i][1]
	if y >= m:
		print(i + 1, a + 1)
		exit(0)
	else:
		m = y
		a = i
print(-1, -1)


def solve():
	n = int(input())
	segs = []
	for i in range(n):
		t = tuple(map(int, input().split()))
		segs.append((*t, i))
	segs.sort(key=lambda t: (t[0], -t[1]))
	maxindex = 0
	maxright = 0
	for t in segs:
		if t[1] <= maxright:
			return (t[2] + 1, maxindex + 1)
		else:
			maxindex = t[2]
			maxright = t[1]
	return (-1, -1)
print(*solve())


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
n = int(input())
a = [list(rint()) + [i + 1] for i in range(n)]
a.sort(key=lambda aa: [aa[0], -aa[1], aa[2]])
start = [-1, -1, -1]
for aa in a:
	if start[1] >= aa[1]:
		ans = [aa[2], start[2]]
		print(*ans)
		exit()
	else:
		start = aa
print(-1, -1)


n = int(input())
data = [(i, tuple(map(int, input().split()))) for i in range(n)]
data.sort(key=lambda x: x[1][0])
start = (-1, (0, 0))
answer = (-2, -2)
for d in data:
	if d[1][1] <= start[1][1]:
		answer = (start[0], d[0])
		break
	elif d[1][0] == start[1][0] and d[1][1] >= start[1][1]:
		answer = (d[0], start[0])
	else:
		start = d
print('{} {}'.format(answer[1] + 1, answer[0] + 1))


n = int(input())
a = sorted(((l, -r, i) for (l, r, i) in (map(int, input().split() + [i + 1]) for i in range(n))))
print(*next(((y[2], x[2]) for (x, y) in zip(a, a[1:]) if x[1] <= y[1]), (-1, -1)))


N = int(input())
src = [tuple(map(int, input().split() + [i])) for i in range(N)]
src.sort()
prev_l = max_r = 0
prev_i = outer = -1
for (l, r, i) in src:
	if prev_l == l:
		print(prev_i + 1, i + 1)
		exit()
	if r <= max_r:
		print(i + 1, outer + 1)
		exit()
	else:
		max_r = r
		outer = i
	prev_l = l
	prev_i = i
print(-1, -1)


n = int(input())
lst = []
for i in range(n):
	(l, r) = map(int, input().split())
	lstcur = [l, r]
	lst.append(lstcur)
lsts = sorted(lst)
f = False
maxr = -1
maxl = -1
maxi = -1
if n == 1:
	print(-1, -1)
	f = True
for i in range(len(lsts)):
	if f:
		break
	if lsts[i][0] == maxl:
		if lsts[i][1] == maxr:
			print(lst.index([maxl, maxr]) + 1, end=' ')
			lst[lst.index(lsts[i])] = [-1, -1]
			print(lst.index(lsts[i]) + 1)
		else:
			print(lst.index([maxl, maxr]) + 1, lst.index(lsts[i]) + 1)
		f = True
		break
	if lsts[i][1] == maxr:
		print(lst.index(lsts[i]) + 1, lst.index([maxl, maxr]) + 1)
		f = True
		break
	if lsts[i][1] > maxr:
		maxr = lsts[i][1]
		maxl = lsts[i][0]
	if lsts[i][1] < maxr:
		print(lst.index(lsts[i]) + 1, lst.index([maxl, maxr]) + 1)
		f = True
		break
if not f:
	print(-1, -1)


n = int(input())
a = []
for i in range(1, n + 1):
	(l, r) = map(int, input().split())
	a.append((l, r, i))
a.sort()
for i in range(n - 1):
	if a[i][0] == a[i + 1][0]:
		print(str(a[i][2]) + ' ' + str(a[i + 1][2]))
		break
	if a[i][1] >= a[i + 1][1]:
		print(str(a[i + 1][2]) + ' ' + str(a[i][2]))
		break
else:
	print('-1 -1')


n = int(input())
lis = []
for i in range(n):
	(a, b) = map(int, input().split())
	lis.append([a, b, i])
lis.sort()
i = 0
j = 1
while i < n and j < n:
	(a, b, c) = lis[i]
	(d, e, f) = lis[j]
	if b >= e and a <= d:
		print(f + 1, c + 1)
		exit()
	elif a == d and e >= b:
		print(c + 1, f + 1)
		exit()
	i += 1
	j += 1
print(-1, -1)


n = int(input())
a = []
for i in range(n):
	(l, r) = map(int, input().split())
	a.append([l, r, i + 1])
a.sort()
f = 0
for i in range(1, n):
	if a[i][1] <= a[i - 1][1]:
		print(a[i][2], a[i - 1][2])
		f = 1
		break
	elif a[i][1] > a[i - 1][1] and a[i][0] == a[i - 1][0]:
		print(a[i - 1][2], a[i][2])
		f = 1
		break
if f == 0:
	print('-1 -1')


n = int(input())
l = []
for i in range(n):
	(a, b) = list(map(int, input().split()))
	l.append([a, b, i])
l.sort(key=lambda x: (x[0], -x[1], x[2]))
cur = l[0][1]
ind = l[0][2]
for i in range(1, n):
	if cur >= l[i][1]:
		print(l[i][2] + 1, ind + 1)
		exit()
	else:
		cur = l[i][1]
		ind = l[i][2]
print(-1, -1)


n = int(input())
a = []
for i in range(n):
	a.append(list(map(int, input().split())) + [i + 1])
a.sort(key=lambda e: e[0])
f = 0
for i in range(n - 1):
	if a[i][0] == a[i + 1][0]:
		if a[i][1] >= a[i + 1][1]:
			print(a[i + 1][2], a[i][2])
		else:
			print(a[i][2], a[i + 1][2])
		f = 1
		break
	if a[i][1] >= a[i + 1][1]:
		f = 1
		print(a[i + 1][2], a[i][2])
		break
if f == 0:
	print(-1, -1)


n = int(input())
l = [i for i in range(n)]
d = [tuple(map(int, input().split())) for _ in range(n)]
l.sort(key=lambda x: (d[x][0], -d[x][1]))
for i in range(n - 1):
	if d[l[i + 1]][1] <= d[l[i]][1]:
		print(l[i + 1] + 1, l[i] + 1)
		exit()
print(-1, -1)


n = int(input())
segments = []
for _ in range(n):
	(x, y) = map(int, input().split())
	segments.append((x, y))
original = segments
segments = sorted(segments, key=lambda seg: seg[1], reverse=True)
segments = sorted(segments, key=lambda seg: seg[0], reverse=False)
max_seg = (-1, -1)
output = False
for i in range(n):
	if segments[i][1] > max_seg[0]:
		max_seg = (segments[i][1], i)
	else:
		fst = original.index(segments[i]) + 1
		original[fst - 1] = (-1, -1)
		snd = original.index(segments[max_seg[1]]) + 1
		print(str(fst) + ' ' + str(snd))
		output = True
		break
if not output:
	print('-1 -1')


n = int(input())
L = []
for i in range(n):
	(l, r) = map(int, input().split())
	L.append((l, -r, i + 1))
L = sorted(L)
f = 0
for i in range(1, n):
	if L[i - 1][1] <= L[i][1]:
		f = 1
		print(L[i][2], L[i - 1][2])
		break
if f == 0:
	print(-1, -1)


import sys
input = sys.stdin.readline
n = int(input())
c = []
for _ in range(n):
	(a, b) = map(int, input().split())
	c.append((a, b, _))
c.sort(key=lambda x: (x[0], -x[1]))
a = c[0][1]
b = c[0][2]
an1 = -1
an2 = -1
for i in range(1, n):
	if c[i][1] <= a:
		an2 = b + 1
		an1 = c[i][2] + 1
		break
	else:
		a = c[i][1]
		b = c[i][2]
print(an1, an2)


import heapq as hq
seq = []
n = int(input())
for i in range(n):
	[l, r] = [int(x) for x in input().split()]
	seq.append((l, -r, i + 1))
seq.sort()
ans = (-1, -1)
for i in range(n - 1):
	if seq[i][1] <= seq[i + 1][1]:
		ans = (seq[i + 1][2], seq[i][2])
		break
print(ans[0], ans[1])


import sys
n = int(sys.stdin.readline())
intervals = list([(int(x[0]), int(x[1])) for x in list(map(str.split, sys.stdin.readlines()))])
intervals = list(enumerate(intervals))
intervals.sort(key=lambda x: 1000000009 * x[1][0] - x[1][1])
r = 0
ans1 = -1
ans2 = -1
for interval in intervals:
	if interval[1][1] <= r:
		ans1 = interval[0]
		break
	else:
		ans2 = interval[0]
		r = interval[1][1]
if ans1 == -1:
	print('-1 -1')
else:
	print(ans1 + 1, ans2 + 1)


def ordena(e):
	return e[0]
ai = -1
aj = -1
qtdSeg = int(input())
segs = []
for i in range(qtdSeg):
	(ini, fim) = input().split()
	ini = int(ini)
	fim = int(fim)
	segs.append((ini, fim, i + 1))
segs.sort(key=ordena, reverse=True)
for i in range(len(segs) - 1):
	if segs[i][0] == segs[i + 1][0]:
		if segs[i][1] <= segs[i + 1][1]:
			ai = segs[i][2]
			aj = segs[i + 1][2]
			break
		elif segs[i][1] >= segs[i + 1][1]:
			ai = segs[i + 1][2]
			aj = segs[i][2]
			break
	elif segs[i][1] <= segs[i + 1][1]:
		ai = segs[i][2]
		aj = segs[i + 1][2]
		break
print(str(ai) + ' ' + str(aj))


n = int(input())
segs = []
for i in range(n):
	(a, b) = map(int, input().split())
	segs.append([a, b, i])
segs.sort(key=lambda x: [x[0], -x[1]])
for i in range(1, n):
	if segs[i][1] <= segs[i - 1][1]:
		print(segs[i][2] + 1, segs[i - 1][2] + 1)
		exit()
segs.sort(key=lambda x: [-x[1], x[0]])
for i in range(1, n):
	if segs[i][0] >= segs[0][0]:
		print(segs[i][2] + 1, segs[0][2] + 1)
		exit()
print('-1 -1')


def ordena(e):
	return e[0]
ai = -1
aj = -1
qs = int(input())
segs = []
for i in range(qs):
	(init, end) = input().split()
	init = int(init)
	end = int(end)
	segs.append((init, end, i + 1))
segs.sort(key=ordena, reverse=True)
for i in range(len(segs) - 1):
	if segs[i][0] == segs[i + 1][0]:
		if segs[i][1] <= segs[i + 1][1]:
			ai = segs[i][2]
			aj = segs[i + 1][2]
			break
		elif segs[i][1] >= segs[i + 1][1]:
			ai = segs[i + 1][2]
			aj = segs[i][2]
			break
	elif segs[i][1] <= segs[i + 1][1]:
		ai = segs[i][2]
		aj = segs[i + 1][2]
		break
print(str(ai) + ' ' + str(aj))


n = int(input())
segs = []
for seg in range(n):
	(a, b) = map(int, input().split())
	segs.append((a, -b, seg + 1))
segs.sort()
for i in range(1, n):
	e = segs[i]
	if e[1] >= segs[i - 1][1]:
		print(segs[i][2], segs[i - 1][2])
		break
else:
	print(-1, -1)


def main():
	n = int(input())
	segs = []
	for i in range(n):
		inpt = list(map(int, input().split()))
		segs.append((inpt[0], inpt[1], i + 1))
	segs.sort(key=lambda x: x[1], reverse=True)
	segs.sort(key=lambda x: x[0])
	old = segs[0]
	for i in range(1, n):
		current = segs[i]
		if current[1] <= old[1]:
			print(str(current[2]) + ' ' + str(old[2]))
			exit(0)
		elif old[1] < current[1]:
			old = current
	print(str(-1) + ' ' + str(-1))
main()


n = int(input())
a = []
for i in range(1, n + 1):
	(l, r) = map(int, input().split())
	a.append([l, -r, i])
a.sort()
hh = a[0][1]
wahh = max(-1, a[0][2])
for i in range(1, n):
	if a[i][1] >= hh:
		print(a[i][2], wahh)
		exit()
	else:
		hh = a[i][1]
		wahh = a[i][2]
print(-1, -1)


def main():
	n = int(input())
	o = []
	min_r = 0
	min_r_i = 0
	min_r_l = 10000000000000
	for i in range(n):
		(l, r) = [int(x) for x in input().split()]
		o.append([l, r, i])
	o.sort()
	for i in range(1, n):
		if o[i][0] == o[i - 1][0]:
			if o[i][1] >= o[i - 1][1]:
				print(o[i - 1][2] + 1, o[i][2] + 1)
				exit()
		if o[i][1] <= o[i - 1][1]:
			print(o[i][2] + 1, o[i - 1][2] + 1)
			exit()
	print(-1, -1)
main()