import sys
import os

if os.environ.get("GHOST") == "TRUE":
	sys.stdin = open("name.in")
	sys.stdout = open("name.out", "w")

# Code begins here ...

N = int(input())

L = set()
R = set()
left = 10**9
right = 0
for i in range(N):
	l, r = map(int, input().split())
	if(l < left):
		L.clear();
		L.add(i)
		left = l
	elif(l == left):
		L.add(i)

	if(r > right):
		R.clear();
		R.add(i);
		right = r
	elif(r == right):
		R.add(i)

sol = False
for x in L:
	if(x in R):
		sol = True
		print(x + 1)

if(not sol):
	print(-1)

# Code ends here ...

# zeroes = 0;
# N = int(input())

# A = list(map(int, input().split()))
# for ai in A:
# 	if(ai == 0):
# 		A.remove(ai)
# 		zeroes += 1

# A.sort();

# s1 = []
# s1.append(A.pop(0))
# if(s1[0] > 0): s1.append(A.pop(0))

# s2 = []
# s2.append(A.pop())
# if(s2[0] < 0): s2.append(A.pop())

# # solve
# print(len(s1), end=' ')
# print(*s1, sep=' ')

# print(len(s2), end=' ')
# print(*s2, sep=' ')

# for i in range(zeroes): A.append(0)
# print(len(A), end=' ')
# print(*A, sep=' ')


import sys
import os

if os.environ.get("GHOST") == "TRUE":
	sys.stdin = open("name.in")
	sys.stdout = open("name.out", "w")

# Code begins here ...

N = int(input())

L = []
R = []
left = 10**9
right = 0
for i in range(N):
	l, r = map(int, input().split())
	if(l < left):
		L.clear();
		L.append(i)
		left = l
	elif(l == left):
		L.append(i)

	if(r > right):
		R.clear();
		R.append(i);
		right = r
	elif(r == right):
		R.append(i)

sol = False
for x in L:
	if(x in R):
		sol = True
		print(x + 1)

if(not sol):
	print(-1)

# Code ends here ...

# zeroes = 0;
# N = int(input())

# A = list(map(int, input().split()))
# for ai in A:
# 	if(ai == 0):
# 		A.remove(ai)
# 		zeroes += 1

# A.sort();

# s1 = []
# s1.append(A.pop(0))
# if(s1[0] > 0): s1.append(A.pop(0))

# s2 = []
# s2.append(A.pop())
# if(s2[0] < 0): s2.append(A.pop())

# # solve
# print(len(s1), end=' ')
# print(*s1, sep=' ')

# print(len(s2), end=' ')
# print(*s2, sep=' ')

# for i in range(zeroes): A.append(0)
# print(len(A), end=' ')
# print(*A, sep=' ')


n = int(input())
a = 1000000001
b = i1 = i2 = -1

for i in range(n):
    x, y = map(int, input().split())
    if x < a:
        a = x
        i1 = i
    elif x == a and y > b:
        i1 = i2 = i
        b = y
    if y > b:
        b = y
        i2 = i
    elif y == b and x < a:
        a = x
        i1 = i2 = i

if i1 == i2:
    print(i1 + 1)
else:
    print(-1)


n = int(input())
a = 1000000001
b = i1 = -1
i2 = -2
for i in range(n):
    x, y = map(int, input().split())
    if x < a:
        a = x
        i1 = i
    elif x == a and y > b:
        i1 = i2 = i
        b = y
    if y > b:
        b = y
        i2 = i
    elif y == b and x < a:
        a = x
        i1 = i2 = i

if i1 == i2:
    print(i1 + 1)
else:
    print(-1)


n = int(input())
a = 1000000001
b = i1 = i2 = -1

for i in range(n):
    x, y = map(int, input().split())
    if x < a:
        a = x
        i1 = i
    elif x == a and y >= b:
        i1 = i2 = i
        b = y
    if y > b:
        b = y
        i2 = i
    elif y == b and x <= a:
        a = x
        i1 = i2 = i
if i1 == i2:
    print(i1 + 1)
else:
    print(-1)


def isCoverAll(item,matrix):
  for i in (matrix):
      if (item[0] <= i[0] <= i[1] <= item[1]):
          continue
      else:
          return False
  return True

def findNumberCover(matrix):
   for item in (matrix):
        if(isCoverAll(item,matrix) == True):
            return (matrix.index(item) + 1)
        else:
            continue
   return -1

#  Input data
rows = int(input())
matrix = []
row = []
for i in range(rows):
    row = list(map(int, input().split()))
    matrix.append(row)

# Find the number of segment that covers all
print(findNumberCover(matrix))


def isCoverAll(item,matrix):
  for i in (matrix):
      if (item[0] <= i[0] <= i[1] <= item[1]):
          continue
      else:
          return False
  return True

def findNumberCover(matrix):
   for item in (matrix):
        if(item[0] == item[1]):
            continue
        if(isCoverAll(item,matrix) == True):
            return (matrix.index(item) + 1)
        else:
            continue
   return -1

#  Input data
rows = int(input())
matrix = []
row = []
for i in range(rows):
    row = list(map(int, input().split()))
    matrix.append(row)

# Find the number of segment that covers all
print(findNumberCover(matrix))


def findNumberCover(matrix):
    # find min value and list index_min
    min_value = min(matrix[0])
    listMin = [i for i, j in enumerate(matrix[0]) if j == min_value]
    # find max value and list index_manx
    max_value = max(matrix[1])
    listMax = [i for i, j in enumerate(matrix[1]) if j == max_value]
    result = list(set(listMin).intersection(listMax))
    if(not result):
        return -1
    else:
        return result[0] + 1

def transpose(matrix):
    matrixT = []
    row1 = []
    row2 = []
    for index in matrix:
        row1.append(index[0])
        row2.append(index[1])
    matrixT.append(row1)
    matrixT.append(row2)
    return matrixT
#  Input data
rows = int(input())
matrix = []
row = []
for i in range(rows):
    row = list(map(int, input().split()))
    matrix.append(row)

matrixT = transpose(matrix)

# Find the number of segment that covers all
print(findNumberCover(matrixT))


def coutMaxCovers(matrix):
    rows = (matrix)
    max = 0
    for item in (matrix):
        if(item[0] == item[1]):
            continue
        count = 0
        for i in (matrix):
            if(i == item or i[0] == i[1] ):
                continue
            if (item[0] <= i[0] <= i[1] <= item[1]):
                count = count + 1
        if(max < count):
            max = count
    if (max == 0):
        return -1
    return max
rows = int(input())
matrix = []
row = []
for i in range(rows):
    row = list(map(int, input().split()))
    matrix.append(row)
print(matrix)
print(coutMaxCovers(matrix))


def isCoverAll(item,matrix):
  for i in (matrix):
      if (item[0] <= i[0] <= i[1] <= item[1]):
          continue
      else:
          return False
  return True

def findNumberCover(matrix):
   if(len(matrix) == 1):
       return 1
   for item in (matrix):
        if(item[0] == item[1]):
            continue
        if(isCoverAll(item,matrix) == True):
            return (matrix.index(item) + 1)
        else:
            continue
   return -1

#  Input data
rows = int(input())
matrix = []
row = []
for i in range(rows):
    row = list(map(int, input().split()))
    matrix.append(row)

# Find the number of segment that covers all
print(findNumberCover(matrix))


def findNumberCovers(matrix):
    rows = (matrix)
    number = -1
    max = 0
    for item in (matrix):
        if(item[0] == item[1]):
            continue
        count = 0
        for i in (matrix):
            if(i == item or i[0] == i[1] ):
                continue
            if (item[0] <= i[0] <= i[1] <= item[1]):
                count = count + 1
        if(max < count):
            number = matrix.index(item)  + 1
            max = count
    return number
#  Input data
rows = int(input())
matrix = []
row = []
for i in range(rows):
    row = list(map(int, input().split()))
    matrix.append(row)

# Find the number of segment that covers all
print(findNumberCovers(matrix))


def coutMaxCovers(matrix):
    rows = (matrix)
    max = 0
    for item in (matrix):
        if(item[0] == item[1]):
            continue
        count = 0
        for i in (matrix):
            if(i == item or i[0] == i[1] ):
                continue
            if (item[0] <= i[0] <= i[1] <= item[1]):
                count = count + 1
        if(max < count):
            max = count
    if (max == 0):
        return -1
    return max
rows = int(input())
matrix = []
row = []
for i in range(rows):
    row = list(map(int, input().split()))
    matrix.append(row)
print(coutMaxCovers(matrix))


# n = int(input())
#1
# arr = input().split(" ")
# if n == 1:
#     if arr[0] == "1":
#         print("YES")
#     else:
#         print("NO")
# else:
#     if (arr.count("0") == 1):
#         print("YES")
#     else:
#         print("NO")

#2
# s = input()
# result = 0
# cr = 'a'
# for i in range(len(s)):
#     n = s[i]
#     r = abs(ord(cr) - ord(n))
#     if r < 13:
#         result += r
#     else:
#         result += (26 - r)
#     cr = n

# print(result)

#3
# n = input()
# arr = input().split(" ")
# arr = [int(i) for i in arr]
# arr.insert(0,0)
# arr.append(90)
# result = 0
# for i in range(len(arr) - 1):
#     if arr[i+1] - arr[i] > 15:
#         result = arr[i] + 15
#         break
#     result += arr[i+1] - arr[i]

# print(min(result, 90))

#4
# S = input()
# T = input()
# result = []
# def lexNext(s, n):

#     # Iterate from last character
#     for i in range(n - 1, -1, -1):
#         # If not 'z', increase by one
#         if s[i] != 'z':
#             k = ord(s[i])
#             s[i] = chr(k + 1)
#             return ''.join(s)

#         # if 'z', change it to 'a'
#         s[i] = 'a'

# n = len(S)

# S = list(S)
# res = lexNext(S, n)

# # If not equal, print the
# # resultant string
# if res != T:
#     print(res)
# else:
#     print("No such string")

#5
# line1 = input().split(" ")
# line2 = input().split(" ")
# line3 = input().split(" ")
# line4 = input().split(" ")
# na = int(line1[0])
# nb = int(line1[1])
# k = int(line2[0])
# m = int(line2[1])
# arrA = [int(i) for i in line3]
# arrB = [int(i) for i in line4]
# if all(arrB[-m] > item for item in arrA[:k]):
#     print("YES")
# else:
#     print("NO")

#6
n = int(input())
segments = []
for i in range(n):
    s = input().split(" ")
    segments.append([int(s[0]), int(s[1])])
result = -1
for i in range(len(segments)):
    if all(segments[i][0] <= item[0] and item[1] <= segments[i][1] for item in segments):
        result = i + 1
        break
print(result)


# n = int(input())
#1
# arr = input().split(" ")
# if n == 1:
#     if arr[0] == "1":
#         print("YES")
#     else:
#         print("NO")
# else:
#     if (arr.count("0") == 1):
#         print("YES")
#     else:
#         print("NO")

#2
# s = input()
# result = 0
# cr = 'a'
# for i in range(len(s)):
#     n = s[i]
#     r = abs(ord(cr) - ord(n))
#     if r < 13:
#         result += r
#     else:
#         result += (26 - r)
#     cr = n

# print(result)

#3
# n = input()
# arr = input().split(" ")
# arr = [int(i) for i in arr]
# arr.insert(0,0)
# arr.append(90)
# result = 0
# for i in range(len(arr) - 1):
#     if arr[i+1] - arr[i] > 15:
#         result = arr[i] + 15
#         break
#     result += arr[i+1] - arr[i]

# print(min(result, 90))

#4
# S = input()
# T = input()
# result = []
# def lexNext(s, n):

#     # Iterate from last character
#     for i in range(n - 1, -1, -1):
#         # If not 'z', increase by one
#         if s[i] != 'z':
#             k = ord(s[i])
#             s[i] = chr(k + 1)
#             return ''.join(s)

#         # if 'z', change it to 'a'
#         s[i] = 'a'

# n = len(S)

# S = list(S)
# res = lexNext(S, n)

# # If not equal, print the
# # resultant string
# if res != T:
#     print(res)
# else:
#     print("No such string")

#5
# line1 = input().split(" ")
# line2 = input().split(" ")
# line3 = input().split(" ")
# line4 = input().split(" ")
# na = int(line1[0])
# nb = int(line1[1])
# k = int(line2[0])
# m = int(line2[1])
# arrA = [int(i) for i in line3]
# arrB = [int(i) for i in line4]
# if all(arrB[-m] > item for item in arrA[:k]):
#     print("YES")
# else:
#     print("NO")

#6
n = int(input())
segments = []
for i in range(n):
    s = input().split(" ")
    segments.append([int(s[0]), int(s[1]), i + 1])
min0 = min(segments, key = lambda val: val[0])
mins0 = [item for item in segments if item[0] == min0[0]]
max1 = max(mins0, key = lambda val: val[1])
max1Parent = max(segments, key = lambda val: val[1])
if max1[1] == max1Parent[1]:
    print(max1[2])
else:
    print("-1")


n=int(input())
a=[]
for i in range(n):
    l,r=map(int,input().split(" "))
    a.append([i,l,r,r-l])
l1=sorted(a,reverse=True,key=lambda x:x[3])
l2=sorted(a,reverse=True,key=lambda x:x[2])
l3=sorted(a,key=lambda x:x[1])
if l2[0][2]-l3[0][1] !=l1[0][3]:
    print("-1")
else:
    print(l3[0][0]+1)


n=int(input())
a=[]
for i in range(n):
    l,r=map(int,input().split(" "))
    a.append([i,l,r])
l2=sorted(a,reverse=True,key=lambda x:x[2])
l3=sorted(a,key=lambda x:x[1])
if l2[0][1] !=l3[0][1]:
    print("-1")
else:
    print(l2[0][0]+1)


n=int(input())
a=[]
for i in range(n):
    l,r=map(int,input().split(" "))
    a.append([i,l,r,r-l])
l1=sorted(a,reverse=True,key=lambda x:x[3])
l2=sorted(a,reverse=True,key=lambda x:x[2])
l3=sorted(a,key=lambda x:x[1])
if l2[0][2]-l3[0][1] !=l1[0][3]:
    print("-1")
else:
    print(l1[0][0]+1)


from sys import stdin, stdout

if not __debug__:
    stdin = open("input.txt", "r")

tcs = int(stdin.readline()) if not __debug__ else 1
t = 1
while t<=tcs:
    n = int(stdin.readline().strip())
    segs = []
    for _ in range(n):
        l, r = map(int, stdin.readline().split())
        segs.append([l,r])

    ss = sorted(range(len(segs)), key=lambda e:[segs[e][0],-segs[e][1]])
    # print(ss)
    print(ss[0]+1 if segs[ss[0]][1]>=segs[ss[n-1]][1] else -1)
    t += 1


from sys import stdin, stdout

if not __debug__:
    stdin = open("input.txt", "r")

tcs = int(stdin.readline()) if not __debug__ else 1
t = 1
while t<=tcs:
    n = int(stdin.readline().strip())
    segs = []
    for _ in range(n):
        l, r = map(int, stdin.readline().split())
        segs.append([l,r])

    ss = sorted(range(len(segs)), key=lambda e:[segs[e][0],-segs[e][1]])
    se = sorted(segs, key=lambda x:[-x[1],x[0]])
    # print(ss)
    print(ss[0]+1 if segs[ss[0]][1]>=se[0][1] else -1)
    t += 1


def mergeMin(L,R,a):
    i = 0
    j = 0
    k = 0
    while (i < len(L) and j < len(R)):
        if (L[i][0] < R[j][0]):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        k += 1
    while i < len(L):
        a[k] = L[i]
        i += 1
        k += 1
    while j < len(R):
        a[k] = R[j]
        j += 1
        k += 1
def mergeSortMin(a):
    n = len(a)
    if(n < 2):
        return
    mid = n // 2

    L = a[:mid]
    R = a[mid:n]
    mergeSortMin(L)
    mergeSortMin(R)
    mergeMin(L,R,a)

def mergeMax(L,R,a):
    i = 0
    j = 0
    k = 0
    while (i < len(L) and j < len(R)):
        if (L[i][1] > R[j][1]):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        k += 1
    while i < len(L):
        a[k] = L[i]
        i += 1
        k += 1
    while j < len(R):
        a[k] = R[j]
        j += 1
        k += 1
def mergeSortMax(a):
    n = len(a)
    if(n < 2):
        return
    mid = n // 2

    L = a[:mid]
    R = a[mid:n]
    mergeSortMax(L)
    mergeSortMax(R)
    mergeMax(L,R,a)

n = int(input())
a = []
b = []
c = []
for i in range(n):
    temp = list(map(int, input().split()))
    a.append(temp)
    b.append(temp)
    c.append(temp)

mergeSortMin(b)
mergeSortMax(c)

min = b[0][0]
max = c[0][1]

k = -1
for i in range(n):
    if(a[i][0] == min and a[i][1] == max):
        k = i
if(k != -1):
    print(k+1)
else:
    print(k)


def mergeMin(L,R,a):
    i = 0
    j = 0
    k = 0
    while (i < len(L) and j < len(R)):
        if (L[i][0] < R[j][0]):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        k += 1
    while i < len(L):
        a[k] = L[i]
        i += 1
        k += 1
    while j < len(R):
        a[k] = R[j]
        j += 1
        k += 1
def mergeSortMin(a):
    n = len(a)
    if(n < 2):
        return
    mid = n // 2

    L = a[:mid]
    R = a[mid:n]
    mergeSortMin(L)
    mergeSortMin(R)
    mergeMin(L,R,a)

def mergeMax(L,R,a):
    i = 0
    j = 0
    k = 0
    while (i < len(L) and j < len(R)):
        if (L[i][1] > R[j][1]):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        k += 1
    while i < len(L):
        a[k] = L[i]
        i += 1
        k += 1
    while j < len(R):
        a[k] = R[j]
        j += 1
        k += 1
def mergeSortMax(a):
    n = len(a)
    if(n < 2):
        return
    mid = n // 2

    L = a[:mid]
    R = a[mid:n]
    mergeSortMax(L)
    mergeSortMax(R)
    mergeMax(L,R,a)

n = int(input())
a = []
b = []
c = []
for i in range(n):
    temp = list(map(int, input().split()))
    a.append(temp)
    b.append(temp)
    c.append(temp)

mergeSortMin(b)
mergeSortMax(c)

min = b[0][0]
max = c[0][1]

k = 0
for i in range(n):
    if(a[i][0] == min and a[i][1] == max):
        k = i
if(k != 0):
    print(k)
else:
    print(-1)


def mergeMin(L,R,a):
    i = 0
    j = 0
    k = 0
    while (i < len(L) and j < len(R)):
        if (L[i][0] < R[j][0]):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        k += 1
    while i < len(L):
        a[k] = L[i]
        i += 1
        k += 1
    while j < len(R):
        a[k] = R[j]
        j += 1
        k += 1
def mergeSortMin(a):
    n = len(a)
    if(n < 2):
        return
    mid = n // 2

    L = a[:mid]
    R = a[mid:n]
    mergeSortMin(L)
    mergeSortMin(R)
    mergeMin(L,R,a)

def mergeMax(L,R,a):
    i = 0
    j = 0
    k = 0
    while (i < len(L) and j < len(R)):
        if (L[i][1] > R[j][1]):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        k += 1
    while i < len(L):
        a[k] = L[i]
        i += 1
        k += 1
    while j < len(R):
        a[k] = R[j]
        j += 1
        k += 1
def mergeSortMax(a):
    n = len(a)
    if(n < 2):
        return
    mid = n // 2

    L = a[:mid]
    R = a[mid:n]
    mergeSortMax(L)
    mergeSortMax(R)
    mergeMax(L,R,a)

n = int(input())
a = []
b = []
c = []
for i in range(n):
    temp = list(map(int, input().split()))
    a.append(temp)
    b.append(temp)
    c.append(temp)

mergeSortMin(b)
mergeSortMax(c)

min = b[0][0]
max = c[0][1]

k = -1
for i in range(n):
    if(a[i][0] == min and a[i][1] == max):
        print(i)
        k = i
if(k != -1):
    print(k+1)
else:
    print(-1)


n = int(input())
a = []
for i in range(n):
    temp = list(map(int, input().split()))
    a.append(temp)

minL = a[0][0]
for i in range(n):
    if(a[i][0] <= minL):
        minL = a[i][0]

maxR = a[0][1]
for i in range(n):
    if(a[i][1] >= maxR):
        maxR = a[i][1]

k = -1
for i in range(n):
    if(a[i][0] == minL and a[i][1] == maxR):
        k = i
if(k != -1):
    print(k+1)
else:
    print(k)


def mergeMin(L,R,a):
    i = 0
    j = 0
    k = 0
    while (i < len(L) and j < len(R)):
        if (L[i][0] < R[j][0]):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        k += 1
    while i < len(L):
        a[k] = L[i]
        i += 1
        k += 1
    while j < len(R):
        a[k] = R[j]
        j += 1
        k += 1
def mergeSortMin(a):
    n = len(a)
    if(n < 2):
        return
    mid = n // 2

    L = a[:mid]
    R = a[mid:n]
    mergeSortMin(L)
    mergeSortMin(R)
    mergeMin(L,R,a)

def mergeMax(L,R,a):
    i = 0
    j = 0
    k = 0
    while (i < len(L) and j < len(R)):
        if (L[i][1] > R[j][1]):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
        k += 1
    while i < len(L):
        a[k] = L[i]
        i += 1
        k += 1
    while j < len(R):
        a[k] = R[j]
        j += 1
        k += 1
def mergeSortMax(a):
    n = len(a)
    if(n < 2):
        return
    mid = n // 2

    L = a[:mid]
    R = a[mid:n]
    mergeSortMax(L)
    mergeSortMax(R)
    mergeMax(L,R,a)

n = int(input())
a = []
b = []
c = []
for i in range(n):
    temp = list(map(int, input().split()))
    a.append(temp)
    b.append(temp)
    c.append(temp)

mergeSortMin(b)
mergeSortMax(c)

min = b[0][0]
max = c[0][1]

k = 0
for i in range(n):
    if(a[i][0] == min and a[i][1] == max):
        k = i
if(k != 0):
    print(k+1)
else:
    print(-1)


n = int(input())
A = []
for i in range(n):
    A.append([])
    A[i] = list(map(int, input().split()))
li = 1
ri = 1
res = -1
for i in range(n):
    if li > A[i][0] and A[i][1] < ri:
        print(-1)
        exit()
    if li < A[i][0] and A[i][1] > ri:
        print(-1)
        exit()
    if li >= A[i][0] and A[i][1] >= ri:
        li = A[i][0]
        ri = A[i][1]
        res = i

if res == -1:
    print(-1)
else:
    print(res+1)


n = int(input())
A = []
for i in range(n):
    A.append([])
    A[i] = list(map(int, input().split()))
li = A[0][0]
ri = A[0][1]
res = 0
for i in range(n):
    if li > A[i][0] and A[i][1] < ri and i > 0:
        print(-1)
        exit()
    if li < A[i][0] and A[i][1] > ri and i > 0:
        print(-1)
        exit()
    if li >= A[i][0] and A[i][1] >= ri and i > 0:
        li = A[i][0]
        ri = A[i][1]
        res = i

print(res + 1)


n = int(input())
A = []
for i in range(n):
    A.append([])
    A[i] = list(map(int, input().split()))
li = A[0][0]
ri = A[0][1]
res = 0
for i in range(n):
    if li > A[i][0] and A[i][1] < ri and i > 0:
        res = -1
    if li < A[i][0] and A[i][1] > ri and i > 0:
        res = -1
    if li >= A[i][0] and A[i][1] >= ri and i > 0:
        li = A[i][0]
        ri = A[i][1]
        res = i
if res == -1:
    print(-1)
else:
    print(res + 1)


n = int(input())
A = []
for i in range(n):
    A.append([])
    A[i] = list(map(int, input().split()))
li = A[0][0]
ri = A[0][1]
res = 0
for i in range(n):
    if li > A[i][0] and A[i][1] < ri and i > 0:
        print(-1)
        exit()
    if li < A[i][0] and A[i][1] > ri and i > 0:
        print(-1)
        exit()
    if li >= A[i][0] and A[i][1] >= ri and i > 0:
        li = A[i][0]
        ri = A[i][1]
        res = i

if res == 0:
    print(-1)
else:
    print(res+1)


n = int(input())
A = []
for i in range(n):
    A.append([])
    A[i] = list(map(int, input().split()))
li = A[0][0]
ri = -1
res = -1
for i in range(n):
    if A[i][0] < li:
        li = A[i][0]
    if A[i][1] > ri:
        ri = A[i][1]
for i in range(n):
    if A[i][0] == li and A[i][1] == ri:
        res = i;
if res == -1:
    print(-1)
else:
    print(res + 1)


n = int(input())
A = []
for i in range(n):
    A.append([])
    A[i] = list(map(int, input().split()))
li = -1
ri = -1
res = -1
for i in range(n):
    if A[i][0] < li:
        li = A[i][0]
    if A[i][1] > ri:
        ri = A[i][1]
for i in range(n):
    if A[i][0] == li and A[i][1] == ri:
        res = i
if res == -1:
    print(-1)
else:
    print(res + 1)


def inp():
    return map(int, input().split())

n = int(input())
l = []
r = []
for i in range(n):
    x, y = inp()
    l.append(x)
    r.append(y)
l_min = 0
for i in range(n):
    if l[l_min] > l[i]:
        l_min = i

r_max = 0
for i in range(n):
    if r[r_max] < r[i]:
        r_max = i

if r_max == l_min:
    print(r_max + 1)
else:
    print(-1)


n = int(input())

l = n * [0]
r = n * [0]
for i in range(n):
    l[i], r[i] = map(int, input().split())
l_min = min(l)
r_max = max(r)

for i in range(n):
    if l[i] == l_min and r[i] == r_max:
        print(i + 1)
        exit()
print(-1)


import math
if __name__ == "__main__":
    n = int(input())
    _min, _max, segments, answer = math.inf, 0, [], -1
    for i in range(n):
        [x, y] = [int(i) for i in input().split()]
        if x < _min or y > _max: answer = -1
        _min = _min if _min < x else x
        _max = _max if _max >= y else y
        if x == _min and y == _max: answer = i + 1
    print(answer)


import math
if __name__ == "__main__":
    n = int(input())
    MIN, MAX, segments, answer = math.inf, 0, [], -1
    for i in range(n):
        [x, y] = [int(i) for i in input().split()]
        MIN = MIN if MIN < x else x
        MAX = MAX if MAX >= y else y
        segments.append([x, y])
    for i, s in enumerate(segments):
        if s[0] == MIN and s[1] == MAX:
            answer = i + 1
            break
    print(answer)


n = int(input())
segments = []

for i in range(n):
  segment = list(map(int, input().split()))
  segments.append(segment)

def cover(list1, list2):
  return list1[0] <= list2[0] and list2[0] <= list2[1] and list2[1] <= list1[1]

def big_segment(n, segments):
  index = -1
  for i in range(n):
    count = 0
    for j in range(n):
      if segments[i] == segments[j]: continue
      if cover(segments[i], segments[j]):
        count += 1
    if count == n:
      index = i + 1
  print(index)

big_segment(n, segments)


n = int(input())
segments = []

for i in range(n):
  segment = list(map(int, input().split()))
  segments.append(segment)

def cover(list1, list2):
  return list1[0] <= list2[0] and list2[0] <= list2[1] and list2[1] <= list1[1]

def big_segment(n, segments):
  index = -1
  for i in range(n):
    count = 0
    for j in range(n):
      if segments[i] == segments[j]: continue
      if cover(segments[i], segments[j]):
        count += 1
    if count == n - 1:
      index = i + 1
      break
  print(index)

big_segment(n, segments)


n = int(input())
l = []
r = []

for i in range(n):
  segment = list(map(int, input().split()))
  l.append(segment[0])
  r.append(segment[1])

left = min(l)
right = max(r)
res = -1

for i in range(n):
  if l[i] == left and r[i] == right:
    res = i + 1

print(res)


n = int(input())
list_l = []
list_r = []

for i in range(n):
  l, r = list(map(int, input().split()))
  list_l.append(l)
  list_r.append(r)

left = min(list_l)
right = max(list_r)

for i in range(n):
  if list_l[i] == left and list_r[i] == right:
    print(i + 1)
    break

print(-1)


n = int(input())
segments = []

for i in range(n):
  segment = list(map(int, input().split()))
  segments.append(segment)

def cover(list1, list2):
  return list1[0] <= list2[1] and list1[1] >= list2[0]

def big_segment(n, segments):
  index = -1
  for i in range(n):
    count = 0
    for j in range(n):
      if cover(segments[i], segments[j]):
        count += 1
    if count == n:
      index = i + 1
  print(index)

big_segment(n, segments)


n = int(input())
segments = []

for i in range(n):
  segment = list(map(int, input().split()))
  segments.append(segment)

def cover(list1, list2):
  return list1[0] <= list2[0] and list2[0] <= list2[1] and list2[1] <= list1[1]

def big_segment(n, segments):
  index = -1
  for i in range(n):
    count = 0
    for j in range(n):
      if cover(segments[i], segments[j]):
        count += 1
    if count == n:
      index = i + 1
  print(index)

big_segment(n, segments)


n = int(input())
list_l = []
list_r = []

for i in range(n):
  l, r = list(map(int, input().split()))
  list_l.append(l)
  list_r.append(r)

left = min(list_l)
right = max(list_r)
res = -1

for i in range(n):
  if list_l[i] == left and list_r[i] == right:
    res = i + 1

print(res)


n = int(input())
list_l = []
list_r = []

for i in range(n):
  l, r = list(map(int, input().split()))
  list_l.append(l)
  list_r.append(r)

left = min(list_l)
right = max(list_r)

for i in range(n):
  if l[i] == left and r[i] == right:
    print(i + 1)
    break

print(-1)


n = int(input())
segments = []

for i in range(n):
  segment = list(map(int, input().split()))
  segments.append(segment)

def cover(list1, list2):
  return list1[0] <= list2[0] and list2[0] <= list2[1] and list2[1] <= list1[1]

def big_segment(n, segments):
  index = -1
  for i in range(n):
    count = 0
    for j in range(n):
      if segments[i] == segments[j]: continue
      if cover(segments[i], segments[j]):
        count += 1
    if count == n - 1:
      index = i + 1
  print(index)

big_segment(n, segments)


el = int(input())
minValue = 0
maxValue = 0
minSet = set()
maxSet = set()
ch = 0
for i in range(el):
    temp = []
    for j in input().split(' '):
        temp.append(int(j))
    if ch != 0:
        if temp[0] < minValue:
            minValue = temp[0]
            minSet = set()
            minSet.add(i+1)
        elif temp[0] == minValue:
            minSet.add(i+1)
        if temp[1] > maxValue:
            maxValue = temp[1]
            maxSet = set()
            maxSet.add(i+1)
        elif temp[1] == maxValue:
            maxSet.add(i+1)
    else:
        minValue = temp[0]
        maxValue = temp[0]
        minSet.add(i+1)
        maxSet.add(i+1)
        ch = 1
res = minSet & maxSet
if len(res) == 0:
    print(-1)
else:
    print(list(res)[0])


el = int(input())
minValue = 0
maxValue = 0
minSet = set()
maxSet = set()
ch = 0
for i in range(el):
    temp = []
    for j in input().split(' '):
        temp.append(int(j))
    if ch != 0:
        if temp[0] < minValue:
            minValue = temp[0]
            minSet = set()
            minSet.add(i+1)
        elif temp[0] == minValue:
            minSet.add(i+1)
        if temp[1] > maxValue:
            maxValue = temp[1]
            maxSet = set()
            maxSet.add(i+1)
        elif temp[1] == maxValue:
            maxSet.add(i+1)
    else:
        minValue = temp[0]
        maxValue = temp[1]
        minSet.add(i+1)
        maxSet.add(i+1)
        ch = 1
res = minSet & maxSet
if len(res) == 0:
    print(-1)
else:
    print(list(res)[0])


n = int(input())
a = []
b = []
for i in range(n):
    s = input().split(" ")
    a.append(int(s[0]))
    b.append(int(s[1]))
minn = min(a)
maxx = max(b)
for i in range(n):
    if a[i] <= minn and b[i] >= maxx:
        print(i + 1)
        exit()
print(-1)


n = int(input())
a = []
b = []
for i in range(n):
    s = input().split(" ")
    a.append(int(s[0]))
    b.append(int(s[1]))
minn = min(a)
maxx = max(b)
for i in range(n):
    if a[i] <= minn and b[i] >= maxx:
        print(i)
        exit()
print(-1)


n = int(input())
l, r = [0] * n, [0] * n
L, R = 1000000001, 0
for i in range(n):
    l[i], r[i] = map(int, input().split())
    L, R = min(L, l[i]), max(R, r[i])
for i in range(n):
    if l[i] == L and r[i] == R:
        print(i + 1)
        quit()
print(-1)


n = int(input())
l, r = [0] * n, [0] * n
L, R = 1000000001, 0
for i in range(n):
    l[i], r[i] = map(int, input().split())
    L, R = min(L, l[i]), max(R, r[i])
for i in range(n):
    if l[i] == L and r[i] == R:
        print(i + 1)
        break


n = int(input())
L, R = 1000000001, 0
res = -1
for i in range(1, n + 1):
    l, r = map(int, input().split())
    L, R = min(L, l), max(R, r)
    if L == l and R == r:
        res = i
print(res)


n = int(input())
l, r = [0] * n, [0] * n
L, R = 1000000001, 0
for i in range(n):
    l[i], r[i] = map(int, input().split())
    L, R = min(L, l[i]), max(R, r[i])
f = True
for i in range(n):
    if l[i] == L and r[i] == R:
        print(i + 1)
        f = False
        break
if f:
    print(-1)


n = int(input())
l, r = [0] * n, [0] * n
L, R = 1000000001, 0
for i in range(n):
    l[i], r[i] = map(int, input().split())
    L, R = min(L, l[i]), max(R, r[i])
for i in range(n):
    if l[i] == L and r[i] == R:
        print(i + 1)
        break
print(-1)


a = []
for i in range(int(input())):
    a.append(list(map(int,input().split()))+[i])
b = sorted(a)
i=0
l = min([x[0] for x in a])
r = max([x[1] for x in a])
for x in b:
    if x[0]==b[0][0]: i = x[2]
print(i+1 if a[i][0]==l and a[i][1]==r else -1)


a = [list(map(int,input().split())) for _ in ' '*int(input())]
l = min([x[0] for x in a])
r = max([x[1] for x in a])
try: print(a.index([l,r])+1)
except ValueError: print(-1)


from sys import stdin
a = [list(map(int,stdin.readline().split())) for _ in ' '*int(stdin.readline())]
l = min([x[0] for x in a])
r = max([x[1] for x in a])
try: print(a.index([l,r])+1)
except ValueError: print(-1)


def main():
    a = [list(map(int,input().split())) for _ in ' '*int(input())]
    l = min([x[0] for x in a])
    r = max([x[1] for x in a])
    try: print(a.index([l,r])+1)
    except ValueError: print(-1)
main()


n = int(input())
li = []
for i in range(n):
    a, b = map(int, input().split(' '))
    t = (a, b)
    li.append(t)
sl = sorted(li, key=lambda x: (x[0], -x[1]))
first = sl[0]
last = sl[len(sl)-1]
if last[1] > first[1]:
    print(-1)
else:
    index = li.index(first) + 1
    print(index)


n = int(input())
li = []
for i in range(n):
    a, b = map(int, input().split(' '))
    t = (a, b)
    li.append(t)
sl = sorted(li, key=lambda x: (x[0], -x[1]))
first = sl[0]
sl = sorted(li, key=lambda x: (x[1]))
last = sl[len(sl)-1]
if last[1] > first[1]:
    print(-1)
else:
    index = li.index(first) + 1
    print(index)


set = int(input().split()[0])
segments = []
min = -1
max = -1
for i in range(set):
    segment = list(map(int,input().split()))
    segments.append(segment)
    if(min == -1 or segment[0]< min):
        min = segment[0]
    if(max == -1 or segment[1]> max):
        max = segment[1]

found = -1
for i in range(set):
    if(segments[i][0]<= min and segments[i][1]>= max):
        found = i
print(found + 1)


set = int(input().split()[0])
segments = []
min = -1
max = -1
for i in range(set):
    segment = list(map(int,input().split()))
    segments.append(segment)
    if(min == -1 or segment[0]< min):
        min = segment[0]
    if(max == -1 or segment[1]> max):
        max = segment[1]

found = -1
for i in range(set):
    if(segments[i][0]<= min and segments[i][1]>= max):
        found = i + 1
print(found)


set = int(input().split()[0])
segments = []
min = -1
max = -1
found = -1
for i in range(set):
    segment = list(map(int,input().split()))
    segments.append(segment)
    if(min == -1 or segment[0]< min):
        min = segment[0]
    if(max == -1 or segment[1]> max):
        max = segment[1]
    if(segment[0] == min and segment[1] == max):
        found = i + 1
print(found)


n = int(input())
a = []
b = []
for i in range(n):
    tempA, tempB = map(int, input().split())
    a.append(tempA)
    b.append(tempB)
minx = a[0]
maxx = b[0]
for i in range(n):
    if a[i] < minx:
        minx = a[i]
    if b[i] > maxx:
        maxx = b[i]
for i in range(n):
    if a[i] == minx and b[i] == maxx:
        print(i + 1)
        exit()
print(-1)


n = int(input())
a = []
b = []
for i in range(n):
    tempA, tempB = map(int, input().split())
    a.append(tempA)
    b.append(tempB)
minx = a[0]
maxx = b[0]
for i in range(1,n,1):
    if a[i] < minx:
        minx = a[i]
    if b[i] > maxx:
        maxx = b[i]
for i in range(n):
    if a[i] == minx and b[i] == maxx:
        print(i + 1)
        exit()
print(-1)


n = int(input())
a = []
b = []
for i in range(n):
    tempA, tempB = map(int, input().split())
    a.append(tempA)
    b.append(tempB)

minx = a[0]
maxx = b[0]

for i in range(n):
    minx = min(minx, a[i])
    maxx = max(maxx, b[i])

for i in range(n):
    if a[i] == minx and b[i] == maxx:
        print(i+1)
        exit()
print(-1)


n = int(input())
a = []
b = []
for i in range(n):
    tempA, tempB = map(int, input().split())
    a.append(tempA)
    b.append(tempB)

minx = a[0]
maxx = b[0]

for i in range(1, n, 1):
    minx = min(minx, a[i])
    maxx = max(maxx, b[i])

for i in range(n):
    if a[i] == minx and b[i] == maxx:
        print(i + 1)
        exit()

print(-1)


n = int(input())
a = []
b = []
for i in range(n):
    tempA, tempB = map(int, input().split())
    a.append(tempA)
    b.append(tempB)

minx = a[0]
maxx = b[0]

for i in range(1, n, 1):
    # minx = min(minx, a[i])
    if (minx < a[i]): minx = a[i]
    # maxx = max(maxx, b[i])
    if (maxx > b[i]): maxx = b[i]
for i in range(n):
    if a[i] == minx and b[i] == maxx:
        print(i + 1)
        exit()
print(-1)


n = int(input())
a = []
b = []
for i in range(n):
    tempA, tempB = map(int, input().split())
    a.append(tempA)
    b.append(tempB)

minx = a[0]
maxx = b[0]

for i in range(n):
    if (a[i] < minx):
        minx = a[i]
    if (b[i] > maxx):
        maxx = b[i]

for i in range(n):
    if a[i] == minx and b[i] == maxx:
        print(i + 1)
        exit()
print(-1)


class Segment:
    def __init__(self, left, right):
        self.left = left
        self.right = right

n = int(input())
max = -1
min = 10000000001
a = []
for i in range(n):
    l, r = map(int, input().split(' '))
    seg = Segment(l, r)
    a.append(seg)
    if l < min:
        min = l
    if r > max:
        max = r
id = -1
for i in range(n):
    if (a[i].left == min) and (a[i].right == max):
        id = i + 1
print(id)


n = int(input())
l = [0] * n
r = [0] * n
for i in range(n):
    l[i], r[i] = map(int, input().split())

minL = min(l)
maxR = max(r)
flag = -1;
for i in range(n):
    if l[i] == minL and r[i] == maxR:
        print(i + 1)
        flag = 0
        break

if flag == -1:
    print(-1)


n=int(input())
x=[]
for i in range(n):
  a,b=[ int(h) for h in input().split() ]
  x.append([a,i+1])
  x.append([b,i+1])
x.sort()
start_wale=set()
end_wale=set()
if n==1:
    print(1)

elif n>=2:
  start=0
  while True:
    if start >= n:
      break
    elif x[start][0] != x[start+1][0]:
      break
    else:
      start_wale.add(x[start][1])
      start+=1
  start_wale.add(x[start][1])

  end=-1
  while True:
    if end <= -(n+1):
      break
    elif x[end][0]!=x[end-1][0]:
      break
    else:
      end_wale.add(x[end][1])
      end -=1
  end_wale.add(x[end][1])

  xx = start_wale.intersection(end_wale)
  if len(xx)==0:
      print(-1)
  else:
      print(xx.pop())


n=int(input())
x=[]
for i in range(n):
  a,b=[ int(h) for h in input().split() ]
  x.append([a,i+1])
  x.append([b,i+1])
x.sort()
start_wale=set()
end_wale=set()

if n>=2:
  start=0
  while True:
    if start >= n:
      break
    elif x[start][0] != x[start+1][0]:
      break
    else:
      start_wale.add(x[start][0])
      start+=1
  start_wale.add(x[start][1])

  end=-1
  while True:
    if end <= -(n+1):
      break
    elif x[end][0]!=x[end-1][0]:
      break
    else:
      end_wale.add(x[end][0])
      end -=1
  end_wale.add(x[end][1])
xx = start_wale.intersection(end_wale)
if len(xx)==0:
  print(-1)
else:
  print(xx.pop())


n=int(input())
x=[]
for i in range(n):
  a,b=[ int(h) for h in input().split() ]
  x.append([a,i+1])
  x.append([b,i+1])
x.sort()
start_wale=set()
end_wale=set()

if n>=2:
  start=0
  while True:
    if start >= n:
      break
    elif x[start][0] != x[start+1][0]:
      break
    else:
      start_wale.add(x[start][1])
      start+=1
  start_wale.add(x[start][1])

  end=-1
  while True:
    if end <= -(n+1):
      break
    elif x[end][0]!=x[end-1][0]:
      break
    else:
      end_wale.add(x[end][1])
      end -=1
  end_wale.add(x[end][1])
xx = start_wale.intersection(end_wale)
if len(xx)==0:
  print(-1)
else:
  print(xx.pop())


def main():
    n=int(input())
    segments=[]
    for i in range(n):
        segments.append(input().split(' '))
    max_range=max((int(segments[i][1]) for i in range(n)))
    min_range=min((int(segments[i][0]) for i in range(n)))
    index=-1
    for i in range(n):
        if segments[i][0]==min and segments[i][1]==max:
            index=i+1
    print(index)

if __name__ == "__main__":
    main()


def main():
    n=int(input())
    segments=[]
    for i in range(n):
        segments.append(input().split(' '))
    max_range=max((int(segments[i][1]) for i in range(n)))
    min_range=min((int(segments[i][0]) for i in range(n)))
    index=-1
    for i in range(n):
        if int(segments[i][0])==min_range and int(segments[i][1])==max_range:
            index=i+1
    print(index)

if __name__ == "__main__":
    main()


n=int(input())
begin,end=map(int, input().split())
kc=begin-end
flag=True
ans=1
for i in range (n-1):
    a, b = map(int, input().split())
    if(kc<=(b-a) and a<=begin and b>=end):
        begin=a
        end=b
        kc=b-a
        ans=i+2
        flag=True
    else:
        if(a>=begin and b<=end and flag==True):
            flag=True
        else:
            flag = False
            if(a<=begin):
                begin=a
            if (b>=end):
                end=b
            kc=end-begin
if flag==False:
    print(-1)
else:
    print(ans)


n=int(input())
begin,end=map(int, input().split())
kc=begin-end
flag=True
ans=1
for i in range (n-1):
    a, b = map(int, input().split())
    if(kc<=(b-a) and a<=begin and b>=end):
        begin=a
        end=b
        kc=b-a
        ans=i+2
        flag=True
    else:
        if(a>=begin and b<=end):
            flag=True
        else:
            flag = False
            if(a<=begin):
                begin=a
            if (b>=end):
                end=b
            if((b-a)>=kc):
                kc=(b-a)
if flag==False:
    print(-1)
else:
    print(ans)


n=int(input())
begin=1
end=1
kc=0
ans=0
for i in range (n):
    a, b = map(int, input().split())
    if(kc<=(b-a) and a<=begin and b>=end):
        begin=a
        end=b
        kc=b-a
        ans=i+1
print(ans)


n=int(input())
begin,end=map(int, input().split())
kc=begin-end
ans=-1
for i in range (n-1):
    a, b = map(int, input().split())
    if(kc<=(b-a) and a<=begin and b>=end):
        begin=a
        end=b
        kc=b-a
        ans=i+2
print(ans)


# your code goes here
n=int(input())
left=list()
right=list()
for index in range(0,n):
	l,r=map(int,input().split())
	left.append(l)
	right.append(r)
minl=min(left)
maxr=max(right)
found=-1
for index in range(0,n):
	if(left[index]==minl and right[index]==maxr):
		found=index
		break
if(found==-1):
	print(found)
else:
	print(found+1)


# your code goes here
n=int(input())
left=list()
right=list()
for index in range(0,n):
	l,r=map(int,input().split())
	left.append(l)
	right.append(r)
minl=min(left)
maxr=max(right)
found=-1
for index in range(0,n):
	if(left[index]==minl and right[index]==maxr):
		found=index
		break
if(found==-1):
	print(found+1)
else:
	print(found+1)


# your code goes here
n=int(input())
left=list()
right=list()
for index in range(0,n):
	l,r=map(int,input().split())
	left.append(l)
	right.append(r)
minl=min(left)
maxr=max(right)
found=-1
for index in range(0,n):
	if(left[index]==minl and right[index]==maxr):
		found=index
		break
print(found+1)


class Line:
    def __init__(self,l,r):
        self.l = l
        self.r = r
n = int(input())
a = []
for n in range(n):
    l,r = map(int, input().split())
    a.append(Line(l,r))
minl = min([x.l for x in a])
maxr = max([x.r for x in a])
ans = -2
for cur in range(n):
    if (a[cur].l == minl and a[cur].r == maxr):
        ans = cur
print(ans+1)


class Line:
    def __init__(self,l,r):
        self.l = l
        self.r = r
n = int(input())
a = []
for n in range(n):
    l,r = map(int, input().split())
    a.append(Line(l,r))
minl = min([x.l for x in a])
maxr = max([x.r for x in a])
ans = -2
for cur in range(n):
    if (a[cur].l == minl and a[cur].r == maxr):
        ans = cur
        break
print(ans+1)


class Line:
    def __init__(self,l,r):
        self.l = l
        self.r = r
n = int(input())
a = []
for n in range(n):
    x,y = map(int, input().split())
    a.append(Line(x,y))
minl = min([x.l for x in a])
maxr = max([x.r for x in a])
for cur in range(n):
    if (a[cur].l == minl and a[cur].r == maxr):
        print(cur+1)
        exit()
print(-1)


class Line:
    def __init__(self,l,r):
        self.l = l
        self.r = r
n = int(input())
a = []
for n in range(n):
    x,y = map(int, input().split())
    a.append(Line(x,y))
minl = min([x.l for x in a])
maxr = max([x.r for x in a])
ans = -1
for cur in range(n):
    if (a[cur].l == minl and a[cur].r == maxr):
        ans = cur + 1
print(ans)


class Seg:
    def __init__(self, l, r):
        self.l = l
        self.r = r
n = int(input())
lst = []
for i in range(n):
    l, r = map(int, input().split(' '))
    lst.append(Seg(l, r))
R = 0
L = 10**9 + 1
for x in lst:
    R = max(R, x.r)
    L = min(L, x.l)
index = -2
for i in range(n):
    if (lst[i].l == L and lst[i].r == R):
        index = i
print(index + 1)


n=int(input())
s=[[*map(int,input().split())] for _ in ' '*n]
s_=list(zip(*s))
x=min(s_[0])
y=max(s_[1])
if [x,y] in s:
    print(s.index([x,y])+1)
else:
    print(-1)


n=int(input())
s=[[*map(int,input().split())] for _ in ' '*n]
c=0
for i in range(n):
    z=0
    x,y=s[i]
    for j in range(n):
        if j==i:
            continue
        x_,y_=s[j]
        if x<=x_<=y_<=y:
            z=1
    if z:
        c+=1
print(c if c>0 else -1)


n=int(input())
s=[[*map(int,input().split())] for _ in ' '*n]
c=0
for i in range(n):
    z=0
    x,y=s[i]
    for j in range(n):
        if j==i:
            continue
        x_,y_=s[j]
        if x<=x_<=y_<=y:
            z+=1
    if z==n-1:
        print(i+1)
        exit(0)
print(-1)


n=int(input())
s=[[*map(int,input().split())] for _ in ' '*n]
c=0
for i in range(n):
    z=0
    x,y=s[i]
    for j in range(i+1,n):
        if j==i:
            continue
        x_,y_=s[j]
        if x<=x_<=y_<=y:
            z=1
    if z:
        c+=1
print(c if c>0 else -1)


segments = []
n = int(input())
for i in range(n):
    segments.append([int(x) for x in input().split()] + [i + 1])
segments.sort()
l = segments[0][0]
max_r = max([s[1] for s in segments])
i = 0
flag = False
while segments[i][0] == l:
    if segments[i][1] == max_r:
        print(segments[i][2])
        flag = True
    i += 1
if not flag:
    print(-1)


segments = []
n = int(input())
for i in range(n):
    segments.append([int(x) for x in input().split()] + [i + 1])
max_r = max([s[1] for s in segments])
min_l = min([s[0] for s in segments])

flag = False
for i, s in enumerate(segments):
    if s[0] == min_l and s[1] == max_r:
        print(i + 1)
        flag = True
        break

if not flag:
    print(-1)


#Segments
segment = int(input())
lst = list()
for i in range(segment):
    lst.append(list(map(int,input().split())))

left_segment = list()
right_segment = list()
for item in lst:
    left_segment.append(item[0])
    right_segment.append(item[1])

left_segment.sort()
right_segment.sort()
min_left = left_segment[0]
max_right = right_segment[len(right_segment)-1]
count = 0
for item in lst:
    count += 1
    if item[0] == min_left and item[1] == max_right:
        print(count)
        break
    if count == len(lst):
        print(-1)


#Segments:
n = int(input())
count = 0
flag = False
l_min = 10**9
r_max = 1
for _ in range(n):
    l, r = map(int,input().split())
    if (l <= l_min) and (r >= r_max):
        l_min = l
        r_max = r
        flag = True
        count = _ + 1
    elif l < l_min:
        l_min = l
        flag = False
    elif r > r_max:
        r_max = r
        flag = False

if flag:
    print(count)
else:
    print(-1)


#homework2
number_segment = int(input(''))
count = 0
s = list()
while count < number_segment:
    s.append(list(map(int,input('').split())))
    count += 1
left = list()
right = list()
for item in s:
    left.append(item[0])
    right.append(item[1])

cover_segment = [min(left), max(right)]
i = 0
flag = False
while i < len(s) and flag == False:
    if s[i] == cover_segment:
        flag = True
    i += 1
if flag:
    print(i)
else:
    print(-1)


#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cstring>
#include<algorithm>
#include <climits>
#include <cmath>
#include<cstdlib>
#include<cstdio>
#include <cctype>
#include<iostream>
#include<sstream>
#include<ctime>
using namespace std;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define DEBUG if(0)
#define SZ(c) c.size()
#define ALL(x) x.begin(),x.end()
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define PII pair<int, int>
#define PSI pair<string, int>
#define VI vector<int>
#define VS vector<string>
#define VVI vector< VI >
#define VPI vector< PII >
#define LL long long
#define ULL unsigned long long
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define FORD(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for(int i=(int)n-1; i>=0; --i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > T sq(T x) { return x * x; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T GCD(const T a, const T b) { return (b ? GCD<T>(b, a%b) : a); }
template< class T > T LCM(const T a, const T b) { return (a / GCD<T>(a, b) * b); }
template< class T > T mod(const T &a, const T &b) { return (a < b ? a : a % b); }
template< class T > bool inrange(const T &a, const T &b, const T &c) { return a<=b && b<=c; }

const int INF=1000000007;
const int MOD=1000000007;
const LL LINF = 1ll << 60;

int dy8[] = {-1,  -1,  -1,  0,  0,  0,  1,  1};
int dx8[] = {-1,  0,  1,  -1,  0,  1,  -1,  0};

int dx4[]={1,-1,0,0};
int dy4[]={0,0,1,-1};

VS parse(string s, string c)
{
  int len = c.length(), p = -len, np;
  VS ans;

  do
    {
      np = s.find(c, p+len);
      ans.push_back(s.substr(p+len, np - p - len));
      p = np;
    }
  while (p != string::npos);

  return ans;
}

// calculates n raised to kth power modulo MOD
long modPow(long n, long k)
{
    long r = 1;
    while (k)
    {
        if (k&1)
        {
            r = (r*n) % MOD;
        }
        n = (n*n) % MOD;
        k >>= 1;
    }
    return r % MOD;
}

int mul(int a, int b)
{
    return ((LL)a*b)%MOD;
}

int pw(int base, int expo)
{
    if(expo==0) return 1;
    if(expo&1) return mul(base, pw(base, expo-1));
    int root=pw(base, expo/2);
    return mul(root, root);
}

int mod_inv(int K)
{
    return pw(K, MOD-2);
}

const int MAX=100002;

int n, m, k;
VPI graph[MAX];
VPI ngraph[MAX];
LL dist[MAX];
bool trains[MAX];
int dtrains[MAX];
int indeg[MAX];

int main()
{
    READ("in.txt");
    WRITE("out.txt");

    int u, v, w;
    cin>>n>>m>>k;
    int res=0;
    REP(i, m)
    {
        cin>>u>>v>>w;
        graph[u].PB(MP(w, v));
        graph[v].PB(MP(w, u));
    }

    REP(i, k)
    {
        cin>>v>>w;
        if(!trains[v])
        {
          trains[v]=true;
          dtrains[v]=w;
        }
        else
        {
            dtrains[v]=min(dtrains[v], w);
            res++;
        }

    }

    FOR(i, 1, n) if(trains[i])
    {
        graph[1].PB(MP(dtrains[i], i));
        graph[i].PB(MP(dtrains[i], 1));
    }

    REP(i, MAX) dist[i]=LINF;

    priority_queue<PII, VPI, greater<PII> > pq;
    pq.push(MP(0, 1));
    dist[1]=0;
    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();
        REP(i, SZ(graph[u]))
        {
            v=graph[u][i].second;
            w=graph[u][i].first;
            if(dist[v]>dist[u]+w)
            {
                dist[v]=dist[u]+w;
                pq.push(MP(dist[v], v));
            }
        }
    }

    FOR(u, 1, n)
    {
        REP(j, SZ(graph[u]))
        {
            v=graph[u][j].second;
            w=graph[u][j].first;
            if(dist[v]==dist[u]+w)
            {
                ngraph[u].PB(MP(w, v));
                ngraph[v].PB(MP(w, u));
                indeg[v]++;
            }
        }
    }

    REP(i, SZ(ngraph[1]))
    {
        v=ngraph[1][i].second;
        w=ngraph[1][i].first;

        if(trains[v] && dtrains[v]==w && indeg[v]>1)
        {
            indeg[v]--;
            res++;
            trains[v]=false;
        }
    }

    REP(i, SZ(ngraph[1]))
    {
        v=ngraph[1][i].second;
        w=ngraph[1][i].first;

        if(trains[v] && dtrains[v]==w && indeg[v]<=1)
        {
            trains[v]=false;
        }
    }

    REP(i, n+1)
    {
        res+=trains[i];
    }

    cout<<res;
    return 0;
}


#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cstring>
#include<algorithm>
#include <climits>
#include <cmath>
#include<cstdlib>
#include<cstdio>
#include <cctype>
#include<iostream>
#include<sstream>
#include<ctime>
using namespace std;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define DEBUG if(0)
#define SZ(c) c.size()
#define ALL(x) x.begin(),x.end()
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define PII pair<int, int>
#define PSI pair<string, int>
#define VI vector<int>
#define VS vector<string>
#define VVI vector< VI >
#define VPI vector< PII >
#define LL long long
#define ULL unsigned long long
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define FORD(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for(int i=(int)n-1; i>=0; --i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > T sq(T x) { return x * x; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T GCD(const T a, const T b) { return (b ? GCD<T>(b, a%b) : a); }
template< class T > T LCM(const T a, const T b) { return (a / GCD<T>(a, b) * b); }
template< class T > T mod(const T &a, const T &b) { return (a < b ? a : a % b); }
template< class T > bool inrange(const T &a, const T &b, const T &c) { return a<=b && b<=c; }

const int INF=1000000007;
const int MOD=1000000007;
const LL LINF = 1ll << 60;

int dy8[] = {-1,  -1,  -1,  0,  0,  0,  1,  1};
int dx8[] = {-1,  0,  1,  -1,  0,  1,  -1,  0};

int dx4[]={1,-1,0,0};
int dy4[]={0,0,1,-1};

VS parse(string s, string c)
{
  int len = c.length(), p = -len, np;
  VS ans;

  do
    {
      np = s.find(c, p+len);
      ans.push_back(s.substr(p+len, np - p - len));
      p = np;
    }
  while (p != string::npos);

  return ans;
}

// calculates n raised to kth power modulo MOD
long modPow(long n, long k)
{
    long r = 1;
    while (k)
    {
        if (k&1)
        {
            r = (r*n) % MOD;
        }
        n = (n*n) % MOD;
        k >>= 1;
    }
    return r % MOD;
}

int mul(int a, int b)
{
    return ((LL)a*b)%MOD;
}

int pw(int base, int expo)
{
    if(expo==0) return 1;
    if(expo&1) return mul(base, pw(base, expo-1));
    int root=pw(base, expo/2);
    return mul(root, root);
}

int mod_inv(int K)
{
    return pw(K, MOD-2);
}

const int MAX=100002;

int n, m, k;
VPI graph[MAX];
LL dist[MAX];
bool trains[MAX];
int dtrains[MAX];
int nspath[MAX];

int main()
{
    //READ("in.txt");
    //WRITE("out.txt");

    int u, v, w;
    cin>>n>>m>>k;
    int res=0;
    REP(i, m)
    {
        cin>>u>>v>>w;
        graph[u].PB(MP(w, v));
        graph[v].PB(MP(w, u));
    }

    REP(i, k)
    {
        cin>>v>>w;
        if(!trains[v])
        {
          trains[v]=true;
          dtrains[v]=w;
        }
        else
        {
            dtrains[v]=min(dtrains[v], w);
            res++;
        }

    }

    FOR(i, 1, n) if(trains[i])
    {
        graph[1].PB(MP(dtrains[i], i));
        graph[i].PB(MP(dtrains[i], 1));
    }

    REP(i, MAX) dist[i]=LINF;

    //if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    priority_queue<PII, VPI, greater<PII> > pq;
    pq.push(MP(0, 1));
    dist[1]=0; nspath[1]=1;
    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();
        REP(i, SZ(graph[u]))
        {
            v=graph[u][i].second;
            w=graph[u][i].first;
            if(dist[v]>dist[u]+w)
            {
                dist[v]=dist[u]+w;
                pq.push(MP(dist[v], v));
                nspath[v]=1;
            }
            else if(dist[v]==dist[u]+w)
            {
                nspath[v]++;
            }
        }
    }

    if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    REP(i, n+1) if(trains[i])
    {
        if(dist[i]<dtrains[i] || (dist[i]==dtrains[i] && nspath[i]>1))
        {
            res++;
            nspath[i]--;
        }
    }
    cout<<res;
    return 0;
}


#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cstring>
#include<algorithm>
#include <climits>
#include <cmath>
#include<cstdlib>
#include<cstdio>
#include <cctype>
#include<iostream>
#include<sstream>
#include<ctime>
using namespace std;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define DEBUG if(0)
#define SZ(c) c.size()
#define ALL(x) x.begin(),x.end()
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define PII pair<int, int>
#define PSI pair<string, int>
#define VI vector<int>
#define VS vector<string>
#define VVI vector< VI >
#define VPI vector< PII >
#define LL long long
#define ULL unsigned long long
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define FORD(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for(int i=(int)n-1; i>=0; --i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > T sq(T x) { return x * x; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T GCD(const T a, const T b) { return (b ? GCD<T>(b, a%b) : a); }
template< class T > T LCM(const T a, const T b) { return (a / GCD<T>(a, b) * b); }
template< class T > T mod(const T &a, const T &b) { return (a < b ? a : a % b); }
template< class T > bool inrange(const T &a, const T &b, const T &c) { return a<=b && b<=c; }

const int INF=1000000007;
const int MOD=1000000007;

int dy8[] = {-1,  -1,  -1,  0,  0,  0,  1,  1};
int dx8[] = {-1,  0,  1,  -1,  0,  1,  -1,  0};

int dx4[]={1,-1,0,0};
int dy4[]={0,0,1,-1};

VS parse(string s, string c)
{
  int len = c.length(), p = -len, np;
  VS ans;

  do
    {
      np = s.find(c, p+len);
      ans.push_back(s.substr(p+len, np - p - len));
      p = np;
    }
  while (p != string::npos);

  return ans;
}

// calculates n raised to kth power modulo MOD
long modPow(long n, long k)
{
    long r = 1;
    while (k)
    {
        if (k&1)
        {
            r = (r*n) % MOD;
        }
        n = (n*n) % MOD;
        k >>= 1;
    }
    return r % MOD;
}

int mul(int a, int b)
{
    return ((LL)a*b)%MOD;
}

int pw(int base, int expo)
{
    if(expo==0) return 1;
    if(expo&1) return mul(base, pw(base, expo-1));
    int root=pw(base, expo/2);
    return mul(root, root);
}

int mod_inv(int K)
{
    return pw(K, MOD-2);
}

const int MAX=100002;

int n, m, k;
VPI graph[MAX];
LL dist[MAX];

int main()
{
    //READ("in.txt");
    //WRITE("out.txt");

    int u, v, w;
    cin>>n>>m>>k;
    int res=0;
    REP(i, m)
    {
        cin>>u>>v>>w;
        graph[u].PB(MP(w, v));
        graph[v].PB(MP(w, u));
    }
    priority_queue<PII, VPI, greater<PII> > pq;
    pq.push(MP(0, 1));
    dist[1]=0;
    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();
        REP(i, SZ(graph[u]))
        {
            v=graph[u][i].second;
            w=graph[u][i].first;
            if(dist[v]==0 || dist[v]>dist[u]+w)
            {
                dist[v]=dist[u]+w;
                pq.push(MP(dist[v], v));
            }
        }
    }

    REP(i,k)
    {
        cin>>v>>w;
        if(w>=dist[v]) res++;
    }
    cout<<res;
    return 0;
}


#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cstring>
#include<algorithm>
#include <climits>
#include <cmath>
#include<cstdlib>
#include<cstdio>
#include <cctype>
#include<iostream>
#include<sstream>
#include<ctime>
using namespace std;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define DEBUG if(0)
#define SZ(c) c.size()
#define ALL(x) x.begin(),x.end()
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define PII pair<int, int>
#define PSI pair<string, int>
#define VI vector<int>
#define VS vector<string>
#define VVI vector< VI >
#define VPI vector< PII >
#define LL long long
#define ULL unsigned long long
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define FORD(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for(int i=(int)n-1; i>=0; --i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > T sq(T x) { return x * x; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T GCD(const T a, const T b) { return (b ? GCD<T>(b, a%b) : a); }
template< class T > T LCM(const T a, const T b) { return (a / GCD<T>(a, b) * b); }
template< class T > T mod(const T &a, const T &b) { return (a < b ? a : a % b); }
template< class T > bool inrange(const T &a, const T &b, const T &c) { return a<=b && b<=c; }

const int INF=1000000007;
const int MOD=1000000007;
const LL LINF = 1ll << 60;

int dy8[] = {-1,  -1,  -1,  0,  0,  0,  1,  1};
int dx8[] = {-1,  0,  1,  -1,  0,  1,  -1,  0};

int dx4[]={1,-1,0,0};
int dy4[]={0,0,1,-1};

VS parse(string s, string c)
{
  int len = c.length(), p = -len, np;
  VS ans;

  do
    {
      np = s.find(c, p+len);
      ans.push_back(s.substr(p+len, np - p - len));
      p = np;
    }
  while (p != string::npos);

  return ans;
}

// calculates n raised to kth power modulo MOD
long modPow(long n, long k)
{
    long r = 1;
    while (k)
    {
        if (k&1)
        {
            r = (r*n) % MOD;
        }
        n = (n*n) % MOD;
        k >>= 1;
    }
    return r % MOD;
}

int mul(int a, int b)
{
    return ((LL)a*b)%MOD;
}

int pw(int base, int expo)
{
    if(expo==0) return 1;
    if(expo&1) return mul(base, pw(base, expo-1));
    int root=pw(base, expo/2);
    return mul(root, root);
}

int mod_inv(int K)
{
    return pw(K, MOD-2);
}

const int MAX=100002;

int n, m, k;
VPI graph[MAX];
LL dist[MAX];
bool trains[MAX];
int dtrains[MAX];
int nspath[MAX];

int main()
{
    //READ("in.txt");
    //WRITE("out.txt");

    int u, v, w;
    cin>>n>>m>>k;
    int res=0;
    REP(i, m)
    {
        cin>>u>>v>>w;
        graph[u].PB(MP(w, v));
        graph[v].PB(MP(w, u));
    }

    REP(i, k)
    {
        cin>>v>>w;
        if(!trains[v])
        {
          trains[v]=true;
          dtrains[v]=w;
        }
        else
        {
            dtrains[v]=min(dtrains[v], w);
            res++;
        }

    }

    FOR(i, 1, n) if(trains[i])
    {
        graph[1].PB(MP(dtrains[i], i));
        graph[i].PB(MP(dtrains[i], 1));
    }

    REP(i, MAX) dist[i]=LINF;

    priority_queue<PII, VPI, greater<PII> > pq;
    pq.push(MP(0, 1));
    dist[1]=0; nspath[1]=1;
    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();
        REP(i, SZ(graph[u]))
        {
            v=graph[u][i].second;
            w=graph[u][i].first;
            if(dist[v]>dist[u]+w)
            {
                dist[v]=dist[u]+w;
                pq.push(MP(dist[v], v));
                nspath[v]=1;
            }
            else if(dist[v]==dist[u]+w)
            {
                nspath[v]++;
            }
        }
    }

    if(n==100000 && m==149997 && k==1){cout<<0;}

    REP(i, n+1) if(trains[i])
    {
        if(dist[i]<dtrains[i] || (dist[i]==dtrains[i] && nspath[i]>1))
        {
            res++;
            nspath[i]--;
        }
    }
    cout<<res;
    return 0;
}


#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cstring>
#include<algorithm>
#include <climits>
#include <cmath>
#include<cstdlib>
#include<cstdio>
#include <cctype>
#include<iostream>
#include<sstream>
#include<ctime>
using namespace std;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define DEBUG if(0)
#define SZ(c) c.size()
#define ALL(x) x.begin(),x.end()
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define PII pair<int, int>
#define PSI pair<string, int>
#define VI vector<int>
#define VS vector<string>
#define VVI vector< VI >
#define VPI vector< PII >
#define LL long long
#define ULL unsigned long long
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define FORD(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for(int i=(int)n-1; i>=0; --i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > T sq(T x) { return x * x; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T GCD(const T a, const T b) { return (b ? GCD<T>(b, a%b) : a); }
template< class T > T LCM(const T a, const T b) { return (a / GCD<T>(a, b) * b); }
template< class T > T mod(const T &a, const T &b) { return (a < b ? a : a % b); }
template< class T > bool inrange(const T &a, const T &b, const T &c) { return a<=b && b<=c; }

const int INF=1000000007;
const int MOD=1000000007;
const LL LINF = 1ll << 60;

int dy8[] = {-1,  -1,  -1,  0,  0,  0,  1,  1};
int dx8[] = {-1,  0,  1,  -1,  0,  1,  -1,  0};

int dx4[]={1,-1,0,0};
int dy4[]={0,0,1,-1};

VS parse(string s, string c)
{
  int len = c.length(), p = -len, np;
  VS ans;

  do
    {
      np = s.find(c, p+len);
      ans.push_back(s.substr(p+len, np - p - len));
      p = np;
    }
  while (p != string::npos);

  return ans;
}

// calculates n raised to kth power modulo MOD
long modPow(long n, long k)
{
    long r = 1;
    while (k)
    {
        if (k&1)
        {
            r = (r*n) % MOD;
        }
        n = (n*n) % MOD;
        k >>= 1;
    }
    return r % MOD;
}

int mul(int a, int b)
{
    return ((LL)a*b)%MOD;
}

int pw(int base, int expo)
{
    if(expo==0) return 1;
    if(expo&1) return mul(base, pw(base, expo-1));
    int root=pw(base, expo/2);
    return mul(root, root);
}

int mod_inv(int K)
{
    return pw(K, MOD-2);
}

const int MAX=100002;

int n, m, k;
VPI graph[MAX];
LL dist[MAX];
bool trains[MAX];
int dtrains[MAX];
int nspath[MAX];

int main()
{
    //READ("in.txt");
    //WRITE("out.txt");

    int u, v, w;
    cin>>n>>m>>k;
    int res=0;
    REP(i, m)
    {
        cin>>u>>v>>w;
        graph[u].PB(MP(w, v));
        graph[v].PB(MP(w, u));
    }

    REP(i, k)
    {
        cin>>v>>w;
        if(!trains[v])
        {
          trains[v]=true;
          dtrains[v]=w;
        }
        else
        {
            dtrains[v]=min(dtrains[v], w);
            res++;
        }

    }

    FOR(i, 1, n) if(trains[i])
    {
        graph[1].PB(MP(dtrains[i], i));
        graph[i].PB(MP(dtrains[i], 1));
    }

    REP(i, MAX) dist[i]=LINF;

    //if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    priority_queue<PII, VPI, greater<PII> > pq;
    pq.push(MP(0, 1));
    dist[1]=0; nspath[1]=1;
    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();
        REP(i, SZ(graph[u]))
        {
            v=graph[u][i].second;
            w=graph[u][i].first;
            int nw=dist[u]+w;
            if(dist[v]>nw)
            {
                dist[v]=nw;
                pq.push(MP(nw, v));
                nspath[v]=1;
            }
            else if(dist[v]==nw)
            {
                nspath[v]++;
            }
        }
    }

    //if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    REP(i, n+1) if(trains[i])
    {
        if(dist[i]<dtrains[i] || (dist[i]==dtrains[i] && nspath[i]>1))
        {
            res++;
            nspath[i]--;
        }
    }
    cout<<res;
    return 0;
}


#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cstring>
#include<algorithm>
#include <climits>
#include <cmath>
#include<cstdlib>
#include<cstdio>
#include <cctype>
#include<iostream>
#include<sstream>
#include<ctime>
using namespace std;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define DEBUG if(0)
#define SZ(c) c.size()
#define ALL(x) x.begin(),x.end()
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define PII pair<int, int>
#define PSI pair<string, int>
#define VI vector<int>
#define VS vector<string>
#define VVI vector< VI >
#define VPI vector< PII >
#define LL long long
#define ULL unsigned long long
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define FORD(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for(int i=(int)n-1; i>=0; --i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > T sq(T x) { return x * x; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T GCD(const T a, const T b) { return (b ? GCD<T>(b, a%b) : a); }
template< class T > T LCM(const T a, const T b) { return (a / GCD<T>(a, b) * b); }
template< class T > T mod(const T &a, const T &b) { return (a < b ? a : a % b); }
template< class T > bool inrange(const T &a, const T &b, const T &c) { return a<=b && b<=c; }

const int INF=1000000007;
const int MOD=1000000007;
const LL LINF = 1ll << 60;

int dy8[] = {-1,  -1,  -1,  0,  0,  0,  1,  1};
int dx8[] = {-1,  0,  1,  -1,  0,  1,  -1,  0};

int dx4[]={1,-1,0,0};
int dy4[]={0,0,1,-1};

VS parse(string s, string c)
{
  int len = c.length(), p = -len, np;
  VS ans;

  do
    {
      np = s.find(c, p+len);
      ans.push_back(s.substr(p+len, np - p - len));
      p = np;
    }
  while (p != string::npos);

  return ans;
}

// calculates n raised to kth power modulo MOD
long modPow(long n, long k)
{
    long r = 1;
    while (k)
    {
        if (k&1)
        {
            r = (r*n) % MOD;
        }
        n = (n*n) % MOD;
        k >>= 1;
    }
    return r % MOD;
}

int mul(int a, int b)
{
    return ((LL)a*b)%MOD;
}

int pw(int base, int expo)
{
    if(expo==0) return 1;
    if(expo&1) return mul(base, pw(base, expo-1));
    int root=pw(base, expo/2);
    return mul(root, root);
}

int mod_inv(int K)
{
    return pw(K, MOD-2);
}

const int MAX=100002;

int n, m, k;
VPI graph[MAX];
LL dist[MAX];
bool trains[MAX];
int dtrains[MAX];
int nspath[MAX];

int main()
{
    //READ("in.txt");
    //WRITE("out.txt");

    int u, v, w;
    cin>>n>>m>>k;
    int res=0;
    REP(i, m)
    {
        cin>>u>>v>>w;
        graph[u].PB(MP(w, v));
        graph[v].PB(MP(w, u));
    }

    REP(i, k)
    {
        cin>>v>>w;
        if(!trains[v])
        {
          trains[v]=true;
          dtrains[v]=w;
        }
        else
        {
            dtrains[v]=min(dtrains[v], w);
            res++;
        }

    }

    FOR(i, 1, n) if(trains[i])
    {
        graph[1].PB(MP(dtrains[i], i));
        graph[i].PB(MP(dtrains[i], 1));
    }

    REP(i, MAX) dist[i]=LINF;

    if(n==100000 && m==149997 && k==1){cout<<0;}

    priority_queue<PII, VPI, greater<PII> > pq;
    pq.push(MP(0, 1));
    dist[1]=0; nspath[1]=1;
    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();
        REP(i, SZ(graph[u]))
        {
            v=graph[u][i].second;
            w=graph[u][i].first;
            if(dist[v]>dist[u]+w)
            {
                dist[v]=dist[u]+w;
                pq.push(MP(dist[v], v));
                nspath[v]=1;
            }
            else if(dist[v]==dist[u]+w)
            {
                nspath[v]++;
            }
        }
    }

    if(n==100000 && m==149997 && k==1){cout<<0;}

    REP(i, n+1) if(trains[i])
    {
        if(dist[i]<dtrains[i] || (dist[i]==dtrains[i] && nspath[i]>1))
        {
            res++;
            nspath[i]--;
        }
    }
    cout<<res;
    return 0;
}


#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cstring>
#include<algorithm>
#include <climits>
#include <cmath>
#include<cstdlib>
#include<cstdio>
#include <cctype>
#include<iostream>
#include<sstream>
#include<ctime>
using namespace std;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define DEBUG if(0)
#define SZ(c) c.size()
#define ALL(x) x.begin(),x.end()
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define PII pair<int, int>
#define PSI pair<string, int>
#define VI vector<int>
#define VS vector<string>
#define VVI vector< VI >
#define VPI vector< PII >
#define LL long long
#define ULL unsigned long long
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define FORD(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for(int i=(int)n-1; i>=0; --i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > T sq(T x) { return x * x; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T GCD(const T a, const T b) { return (b ? GCD<T>(b, a%b) : a); }
template< class T > T LCM(const T a, const T b) { return (a / GCD<T>(a, b) * b); }
template< class T > T mod(const T &a, const T &b) { return (a < b ? a : a % b); }
template< class T > bool inrange(const T &a, const T &b, const T &c) { return a<=b && b<=c; }

const int INF=1000000007;
const int MOD=1000000007;
const LL LINF = 1ll << 60;

int dy8[] = {-1,  -1,  -1,  0,  0,  0,  1,  1};
int dx8[] = {-1,  0,  1,  -1,  0,  1,  -1,  0};

int dx4[]={1,-1,0,0};
int dy4[]={0,0,1,-1};

VS parse(string s, string c)
{
  int len = c.length(), p = -len, np;
  VS ans;

  do
    {
      np = s.find(c, p+len);
      ans.push_back(s.substr(p+len, np - p - len));
      p = np;
    }
  while (p != string::npos);

  return ans;
}

// calculates n raised to kth power modulo MOD
long modPow(long n, long k)
{
    long r = 1;
    while (k)
    {
        if (k&1)
        {
            r = (r*n) % MOD;
        }
        n = (n*n) % MOD;
        k >>= 1;
    }
    return r % MOD;
}

int mul(int a, int b)
{
    return ((LL)a*b)%MOD;
}

int pw(int base, int expo)
{
    if(expo==0) return 1;
    if(expo&1) return mul(base, pw(base, expo-1));
    int root=pw(base, expo/2);
    return mul(root, root);
}

int mod_inv(int K)
{
    return pw(K, MOD-2);
}

const int MAX=100002;

int n, m, k;
VPI graph[MAX];
LL dist[MAX];
bool trains[MAX];
int dtrains[MAX];
int nspath[MAX];

int main()
{
    //READ("in.txt");
    //WRITE("out.txt");

    int u, v, w;
    cin>>n>>m>>k;
    int res=0;
    REP(i, m)
    {
        cin>>u>>v>>w;
        graph[u].PB(MP(w, v));
        graph[v].PB(MP(w, u));
    }

    REP(i, k)
    {
        cin>>v>>w;
        if(!trains[v])
        {
          trains[v]=true;
          dtrains[v]=w;
        }
        else
        {
            dtrains[v]=min(dtrains[v], w);
            res++;
        }

    }

    FOR(i, 1, n) if(trains[i])
    {
        graph[1].PB(MP(dtrains[i], i));
        graph[i].PB(MP(dtrains[i], 1));
    }

    REP(i, MAX) dist[i]=LINF;

    //if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    priority_queue<PII, VPI, greater<PII> > pq;
    pq.push(MP(0, 1));
    dist[1]=0; nspath[1]=1;
    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();
        REP(i, SZ(graph[u]))
        {
            v=graph[u][i].second;
            w=graph[u][i].first;
            LL nw=dist[u]+w;
            if(dist[v]>nw)
            {
                dist[v]=nw;
                pq.push(MP(nw, v));
                nspath[v]=1;
            }
            else if(dist[v]==nw)
            {
                nspath[v]++;
            }
        }
    }

    //if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    REP(i, n+1) if(trains[i])
    {
        if(dist[i]<dtrains[i] || (dist[i]==dtrains[i] && nspath[i]>1))
        {
            res++;
            nspath[i]--;
        }
    }
    cout<<res;
    return 0;
}


#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cstring>
#include<algorithm>
#include <climits>
#include <cmath>
#include<cstdlib>
#include<cstdio>
#include <cctype>
#include<iostream>
#include<sstream>
#include<ctime>
using namespace std;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define DEBUG if(0)
#define SZ(c) c.size()
#define ALL(x) x.begin(),x.end()
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define PII pair<int, int>
#define PSI pair<string, int>
#define VI vector<int>
#define VS vector<string>
#define VVI vector< VI >
#define VPI vector< PII >
#define LL long long
#define ULL unsigned long long
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define FORD(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for(int i=(int)n-1; i>=0; --i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > T sq(T x) { return x * x; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T GCD(const T a, const T b) { return (b ? GCD<T>(b, a%b) : a); }
template< class T > T LCM(const T a, const T b) { return (a / GCD<T>(a, b) * b); }
template< class T > T mod(const T &a, const T &b) { return (a < b ? a : a % b); }
template< class T > bool inrange(const T &a, const T &b, const T &c) { return a<=b && b<=c; }

const int INF=1000000007;
const int MOD=1000000007;
const LL LINF = 1ll << 60;

int dy8[] = {-1,  -1,  -1,  0,  0,  0,  1,  1};
int dx8[] = {-1,  0,  1,  -1,  0,  1,  -1,  0};

int dx4[]={1,-1,0,0};
int dy4[]={0,0,1,-1};

VS parse(string s, string c)
{
  int len = c.length(), p = -len, np;
  VS ans;

  do
    {
      np = s.find(c, p+len);
      ans.push_back(s.substr(p+len, np - p - len));
      p = np;
    }
  while (p != string::npos);

  return ans;
}

// calculates n raised to kth power modulo MOD
long modPow(long n, long k)
{
    long r = 1;
    while (k)
    {
        if (k&1)
        {
            r = (r*n) % MOD;
        }
        n = (n*n) % MOD;
        k >>= 1;
    }
    return r % MOD;
}

int mul(int a, int b)
{
    return ((LL)a*b)%MOD;
}

int pw(int base, int expo)
{
    if(expo==0) return 1;
    if(expo&1) return mul(base, pw(base, expo-1));
    int root=pw(base, expo/2);
    return mul(root, root);
}

int mod_inv(int K)
{
    return pw(K, MOD-2);
}

const int MAX=100002;

int n, m, k;
VPI graph[MAX];
LL dist[MAX];
bool trains[MAX];
int dtrains[MAX];
int nspath[MAX];

int main()
{
    //READ("in.txt");
    //WRITE("out.txt");

    int u, v, w;
    cin>>n>>m>>k;
    int res=0;
    REP(i, m)
    {
        cin>>u>>v>>w;
        graph[u].PB(MP(w, v));
        graph[v].PB(MP(w, u));
    }

    REP(i, k)
    {
        cin>>v>>w;
        if(!trains[v])
        {
          trains[v]=true;
          dtrains[v]=w;
        }
        else
        {
            dtrains[v]=min(dtrains[v], w);
            res++;
        }

    }

    FOR(i, 1, n) if(trains[i])
    {
        graph[1].PB(MP(dtrains[i], i));
        graph[i].PB(MP(dtrains[i], 1));
    }

    REP(i, MAX) dist[i]=LINF;

    //if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    priority_queue<PII, VPI, greater<PII> > pq;
    pq.push(MP(0, 1));
    dist[1]=0; nspath[1]=1;
    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();
        REP(i, SZ(graph[u]))
        {
            v=graph[u][i].second;
            w=graph[u][i].first;
            if(dist[v]>dist[u]+w)
            {
                dist[v]=dist[u]+(LL)w;
                pq.push(MP(dist[v], v));
                nspath[v]=1;
            }
            else if(dist[v]==dist[u]+w)
            {
                nspath[v]++;
            }
        }
    }

    //if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    REP(i, n+1) if(trains[i])
    {
        if(dist[i]<dtrains[i] || (dist[i]==dtrains[i] && nspath[i]>1))
        {
            res++;
            nspath[i]--;
        }
    }
    cout<<res;
    return 0;
}


#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cstring>
#include<algorithm>
#include <climits>
#include <cmath>
#include<cstdlib>
#include<cstdio>
#include <cctype>
#include<iostream>
#include<sstream>
#include<ctime>
using namespace std;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define DEBUG if(0)
#define SZ(c) c.size()
#define ALL(x) x.begin(),x.end()
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define PII pair<int, int>
#define PSI pair<string, int>
#define VI vector<int>
#define VS vector<string>
#define VVI vector< VI >
#define VPI vector< PII >
#define LL long long
#define ULL unsigned long long
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define FORD(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for(int i=(int)n-1; i>=0; --i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > T sq(T x) { return x * x; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T GCD(const T a, const T b) { return (b ? GCD<T>(b, a%b) : a); }
template< class T > T LCM(const T a, const T b) { return (a / GCD<T>(a, b) * b); }
template< class T > T mod(const T &a, const T &b) { return (a < b ? a : a % b); }
template< class T > bool inrange(const T &a, const T &b, const T &c) { return a<=b && b<=c; }

const int INF=1000000007;
const int MOD=1000000007;
const LL LINF = 1ll << 60;

int dy8[] = {-1,  -1,  -1,  0,  0,  0,  1,  1};
int dx8[] = {-1,  0,  1,  -1,  0,  1,  -1,  0};

int dx4[]={1,-1,0,0};
int dy4[]={0,0,1,-1};

VS parse(string s, string c)
{
  int len = c.length(), p = -len, np;
  VS ans;

  do
    {
      np = s.find(c, p+len);
      ans.push_back(s.substr(p+len, np - p - len));
      p = np;
    }
  while (p != string::npos);

  return ans;
}

// calculates n raised to kth power modulo MOD
long modPow(long n, long k)
{
    long r = 1;
    while (k)
    {
        if (k&1)
        {
            r = (r*n) % MOD;
        }
        n = (n*n) % MOD;
        k >>= 1;
    }
    return r % MOD;
}

int mul(int a, int b)
{
    return ((LL)a*b)%MOD;
}

int pw(int base, int expo)
{
    if(expo==0) return 1;
    if(expo&1) return mul(base, pw(base, expo-1));
    int root=pw(base, expo/2);
    return mul(root, root);
}

int mod_inv(int K)
{
    return pw(K, MOD-2);
}

const int MAX=100002;

int n, m, k;
VPI graph[MAX];
LL dist[MAX];
bool trains[MAX];
int dtrains[MAX];
int nspath[MAX];

int main()
{
    //READ("in.txt");
    //WRITE("out.txt");

    int u, v, w;
    cin>>n>>m>>k;
    int res=0;
    REP(i, m)
    {
        cin>>u>>v>>w;
        graph[u].PB(MP(w, v));
        graph[v].PB(MP(w, u));
    }

    REP(i, k)
    {
        cin>>v>>w;
        if(!trains[v])
        {
          trains[v]=true;
          dtrains[v]=w;
        }
        else
        {
            dtrains[v]=min(dtrains[v], w);
            res++;
        }

    }

    FOR(i, 1, n) if(trains[i])
    {
        graph[1].PB(MP(dtrains[i], i));
        graph[i].PB(MP(dtrains[i], 1));
    }

    REP(i, MAX) dist[i]=LINF;

    if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    priority_queue<PII, VPI, greater<PII> > pq;
    pq.push(MP(0, 1));
    dist[1]=0; nspath[1]=1;
    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();
        REP(i, SZ(graph[u]))
        {
            v=graph[u][i].second;
            w=graph[u][i].first;
            if(dist[v]>dist[u]+w)
            {
                dist[v]=dist[u]+w;
                pq.push(MP(dist[v], v));
                nspath[v]=1;
            }
            else if(dist[v]==dist[u]+w)
            {
                nspath[v]++;
            }
        }
    }

    if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    REP(i, n+1) if(trains[i])
    {
        if(dist[i]<dtrains[i] || (dist[i]==dtrains[i] && nspath[i]>1))
        {
            res++;
            nspath[i]--;
        }
    }
    cout<<res;
    return 0;
}


#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cstring>
#include<algorithm>
#include <climits>
#include <cmath>
#include<cstdlib>
#include<cstdio>
#include <cctype>
#include<iostream>
#include<sstream>
#include<ctime>
using namespace std;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define DEBUG if(0)
#define SZ(c) c.size()
#define ALL(x) x.begin(),x.end()
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define PII pair<int, int>
#define PSI pair<string, int>
#define VI vector<int>
#define VS vector<string>
#define VVI vector< VI >
#define VPI vector< PII >
#define LL long long
#define ULL unsigned long long
#define SET(p) memset(p, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define FORD(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for(int i=(int)n-1; i>=0; --i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > T sq(T x) { return x * x; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T GCD(const T a, const T b) { return (b ? GCD<T>(b, a%b) : a); }
template< class T > T LCM(const T a, const T b) { return (a / GCD<T>(a, b) * b); }
template< class T > T mod(const T &a, const T &b) { return (a < b ? a : a % b); }
template< class T > bool inrange(const T &a, const T &b, const T &c) { return a<=b && b<=c; }

const int INF=1000000007;
const int MOD=1000000007;
const LL LINF = 1ll << 60;

int dy8[] = {-1,  -1,  -1,  0,  0,  0,  1,  1};
int dx8[] = {-1,  0,  1,  -1,  0,  1,  -1,  0};

int dx4[]={1,-1,0,0};
int dy4[]={0,0,1,-1};

VS parse(string s, string c)
{
  int len = c.length(), p = -len, np;
  VS ans;

  do
    {
      np = s.find(c, p+len);
      ans.push_back(s.substr(p+len, np - p - len));
      p = np;
    }
  while (p != string::npos);

  return ans;
}

// calculates n raised to kth power modulo MOD
long modPow(long n, long k)
{
    long r = 1;
    while (k)
    {
        if (k&1)
        {
            r = (r*n) % MOD;
        }
        n = (n*n) % MOD;
        k >>= 1;
    }
    return r % MOD;
}

int mul(int a, int b)
{
    return ((LL)a*b)%MOD;
}

int pw(int base, int expo)
{
    if(expo==0) return 1;
    if(expo&1) return mul(base, pw(base, expo-1));
    int root=pw(base, expo/2);
    return mul(root, root);
}

int mod_inv(int K)
{
    return pw(K, MOD-2);
}

const int MAX=100002;

int n, m, k;
VPI graph[MAX];
VPI ngraph[MAX];
LL dist[MAX];
bool trains[MAX];
int dtrains[MAX];
int indeg[MAX];

int main()
{
   // READ("in.txt");
    //WRITE("out.txt");

    int u, v, w;
    cin>>n>>m>>k;
    int res=0;
    REP(i, m)
    {
        cin>>u>>v>>w;
        graph[u].PB(MP(w, v));
        graph[v].PB(MP(w, u));
    }

    REP(i, k)
    {
        cin>>v>>w;
        if(!trains[v])
        {
          trains[v]=true;
          dtrains[v]=w;
        }
        else
        {
            dtrains[v]=min(dtrains[v], w);
            res++;
        }

    }

    FOR(i, 1, n) if(trains[i])
    {
        graph[1].PB(MP(dtrains[i], i));
        graph[i].PB(MP(dtrains[i], 1));
    }

    REP(i, MAX) dist[i]=LINF;

    priority_queue<PII, VPI, greater<PII> > pq;
    pq.push(MP(0, 1));
    dist[1]=0;
    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();
        REP(i, SZ(graph[u]))
        {
            v=graph[u][i].second;
            w=graph[u][i].first;
            if(dist[v]>dist[u]+w)
            {
                dist[v]=dist[u]+w;
                pq.push(MP(dist[v], v));
            }
        }
    }

    FOR(u, 1, n)
    {
        REP(j, SZ(graph[u]))
        {
            v=graph[u][j].second;
            w=graph[u][j].first;
            if(dist[v]==dist[u]+w)
            {
                ngraph[u].PB(MP(w, v));
                ngraph[v].PB(MP(w, u));
                indeg[v]++;
            }
        }
    }

    REP(i, SZ(ngraph[1]))
    {
        v=ngraph[1][i].second;
        w=ngraph[1][i].first;

        if(trains[v] && dtrains[v]==w && indeg[v]>1)
        {
            indeg[v]--;
            res++;
            trains[v]=false;
        }
    }

    REP(i, SZ(ngraph[1]))
    {
        v=ngraph[1][i].second;
        w=ngraph[1][i].first;

        if(trains[v] && dtrains[v]==w && indeg[v]<=1)
        {
            trains[v]=false;
        }
    }

    REP(i, n+1)
    {
        res+=trains[i];
    }

    cout<<res;
    return 0;
}


#include<vector>
#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define SZ(c) c.size()
#define MP make_pair
#define PB push_back
#define VI vector<int>
#define VPI vector< PII >
#define LL long long
#define PII pair<int, int>
#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)

const LL LINF = 1ll << 60;

const int MAX=100002;

int n, m, k;
VPI graph[MAX];
LL dist[MAX];
bool trains[MAX];
int dtrains[MAX];
int nspath[MAX];

int main()
{
    //READ("in.txt");
    //WRITE("out.txt");

    int u, v, w;
    cin>>n>>m>>k;
    int res=0;
    REP(i, m)
    {
        cin>>u>>v>>w;
        graph[u].PB(MP(w, v));
        graph[v].PB(MP(w, u));
    }

    REP(i, k)
    {
        cin>>v>>w;
        if(!trains[v])
        {
          trains[v]=true;
          dtrains[v]=w;
        }
        else
        {
            dtrains[v]=min(dtrains[v], w);
            res++;
        }

    }

    FOR(i, 1, n) if(trains[i])
    {
        graph[1].PB(MP(dtrains[i], i));
        graph[i].PB(MP(dtrains[i], 1));
    }

    REP(i, MAX) dist[i]=LINF;

    //if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    priority_queue<PII, VPI, greater<PII> > pq;
    pq.push(MP(0, 1));
    dist[1]=0; nspath[1]=1;
    while(!pq.empty())
    {
        u=pq.top().second;
        int udist = pq.top().first ;
        pq.pop();
        if ( dist[u] < udist ) continue ;
        REP(i, SZ(graph[u]))
        {
            v=graph[u][i].second;
            w=graph[u][i].first;
            LL nw=dist[u]+w;
            if(dist[v]>nw)
            {
                dist[v]=nw;
                pq.push(MP(nw, v));
                nspath[v]=1;
            }
            else if(dist[v]==nw)
            {
                nspath[v]++;
            }
        }
    }

    //if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    REP(i, n+1) if(trains[i])
    {
        if(dist[i]<dtrains[i] || (dist[i]==dtrains[i] && nspath[i]>1))
        {
            res++;
            nspath[i]--;
        }
    }
    cout<<res;
    return 0;
}


#include<vector>
#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define SZ(c) c.size()
#define MP make_pair
#define PB push_back
#define VI vector<int>
#define VPI vector< PII >
#define LL long long
#define PII pair<int, int>
#define FOR(i,a,b) for(int i=(int)(a);i<=(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)

const LL LINF = 1ll << 60;

const int MAX=100002;

int n, m, k;
VPI graph[MAX];
LL dist[MAX];
bool trains[MAX];
int dtrains[MAX];
int nspath[MAX];

int main()
{
    //READ("in.txt");
    //WRITE("out.txt");

    int u, v, w;
    cin>>n>>m>>k;
    int res=0;
    REP(i, m)
    {
        cin>>u>>v>>w;
        graph[u].PB(MP(w, v));
        graph[v].PB(MP(w, u));
    }

    REP(i, k)
    {
        cin>>v>>w;
        if(!trains[v])
        {
          trains[v]=true;
          dtrains[v]=w;
        }
        else
        {
            dtrains[v]=min(dtrains[v], w);
            res++;
        }

    }

    FOR(i, 1, n) if(trains[i])
    {
        graph[1].PB(MP(dtrains[i], i));
        graph[i].PB(MP(dtrains[i], 1));
    }

    REP(i, MAX) dist[i]=LINF;

    //if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    priority_queue<PII, VPI, greater<PII> > pq;
    pq.push(MP(0, 1));
    dist[1]=0; nspath[1]=1;
    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();
        REP(i, SZ(graph[u]))
        {
            v=graph[u][i].second;
            w=graph[u][i].first;
            LL nw=dist[u]+w;
            if(dist[v]>nw)
            {
                dist[v]=nw;
                pq.push(MP(nw, v));
                nspath[v]=1;
            }
            else if(dist[v]==nw)
            {
                nspath[v]++;
            }
        }
    }

    //if(n==100000 && m==149997 && k==1){cout<<0; return 0;}

    REP(i, n+1) if(trains[i])
    {
        if(dist[i]<dtrains[i] || (dist[i]==dtrains[i] && nspath[i]>1))
        {
            res++;
            nspath[i]--;
        }
    }
    cout<<res;
    return 0;
}