Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.

To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a_1, a_2, ..., a_{k}.

Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.

Formally, Masha will pay x roubles, if she will open the bakery in some city b (a_{i} ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = a_{j} for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).

Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount.


-----Input-----

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 10^5, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively.

Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 10^9, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers .

If k > 0, then the last line of the input contains k distinct integers a_1, a_2, ..., a_{k} (1 ≤ a_{i} ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input.


-----Output-----

Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line.

If the bakery can not be opened (while satisfying conditions) in any of the n cities, print  - 1 in the only line.


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

Output
3
Input
3 1 1
1 2 3
3

Output
-1


-----Note-----

[Image]

Image illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened.

Difficulty: EASY

Solutions:
import sys
(n, m, k) = map(int, sys.stdin.readline().split())
if k == 0:
	print(-1)
	exit()
D = []
for i in range(m):
	(u, v, l) = map(int, sys.stdin.readline().split())
	(u, v) = (u - 1, v - 1)
	D.append((u, v, l))
a = list(map(int, sys.stdin.readline().split()))
F = [False] * n
for i in a:
	F[i - 1] = True
D = sorted(D, key=lambda x: x[2])
for (u, v, l) in D:
	if F[u] and (not F[v]) or (not F[u] and F[v]):
		print(l)
		exit()
print(-1)


import sys
from math import *
import threading
from itertools import count
from pprint import pprint
from collections import defaultdict
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(300000)
mod = 10 ** 9 + 7
inf = 10 ** 15
decision = ['NO', 'YES']
yes = 'YES'
no = 'NO'
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def sumk(a, b):
	print('called for', a, b)
	ans = a * (a + 1) // 2
	ans -= b * (b + 1) // 2
	return ans
karmanya = 0
for _ in range(int(input()) if karmanya else 1):
	(n, m, k) = map(int, input().split())
	a = [input().split() for i in range(m)]
	(s, ans) = (set(), inf)
	if k > 0:
		s = set(input().split())
	for i in a:
		if (i[0] in s) ^ (i[1] in s):
			ans = min(ans, int(i[2]))
	print(-1 if ans == inf else ans)


firstLineOfInput = input().split()
(n, m, k) = (int(firstLineOfInput[0]), int(firstLineOfInput[1]), int(firstLineOfInput[2]))
roads = []
for i in range(m):
	roads.append(input().split())
storageCitys = []
if k > 0:
	storageCitys = input().split()
isStorage = [False for i in range(n + 1)]
for storageCity in storageCitys:
	isStorage[int(storageCity)] = True
minPay = -1
for road in roads:
	aCityOfThisRoad = int(road[0])
	anotherCityOfThisRoad = int(road[1])
	if isStorage[aCityOfThisRoad] and (not isStorage[anotherCityOfThisRoad]) or (not isStorage[aCityOfThisRoad] and isStorage[anotherCityOfThisRoad]):
		lengthOfThisRoad = int(road[2])
		if minPay == -1:
			minPay = lengthOfThisRoad
		elif lengthOfThisRoad < minPay:
			minPay = lengthOfThisRoad
print(minPay)


import sys
(n, m, k) = map(int, input().split())
p = []
for _ in range(m):
	(u, v, l) = map(int, input().split())
	p.append((u, v, l))
if k != 0:
	d = {int(x): 1 for x in input().split()}
	mini = sys.maxsize
	for i in range(m):
		(u, v, l) = p[i]
		if d.get(u) and (not d.get(v)) or (not d.get(u) and d.get(v)):
			if l < mini:
				mini = l
	if mini != sys.maxsize:
		print(mini)
	else:
		print('-1')
else:
	print('-1')


(n, m, k) = map(int, input().split())
if k == 0 or k == n:
	print(-1)
else:
	has = [[] for i in range(n)]
	edge = []
	for i in range(m):
		(a, b, c) = map(int, input().split())
		edge.append([a - 1, b - 1, c])
	bad = [False] * n
	bads = map(int, input().split())
	for i in bads:
		bad[i - 1] = True
	ans = 10 ** 18
	for e in edge:
		if bad[e[0]] != bad[e[1]]:
			ans = min(ans, e[2])
	print(ans if ans < 10 ** 18 else -1)


(n, m, k) = map(int, input().split())
l = []
for i in range(m):
	l.append(list(map(int, input().split())))
if k != 0:
	fluor = set(map(int, input().split()))
if k == 0 or k == n:
	print(-1)
	exit()
bakery = set(range(1, n + 1)) - fluor
res = 10 ** 9 + 1
for (a, b, l) in l:
	if a in bakery and b in fluor or (b in bakery and a in fluor):
		if l < res:
			res = l
if res == 10 ** 9 + 1:
	print(-1)
else:
	print(res)


import sys
inf = float('inf')
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def dfs(i):
	visited[i] = True
	for j in range(n):
		if visited[j]:
			continue
		elif myArr[j][0] == myArr[i][0] or myArr[j][1] == myArr[i][1]:
			dfs(j)

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

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, m, k) = get_ints()
graph = {i: [] for i in range(1, n + 1)}
for i in range(m):
	(x, y, l) = get_ints()
	graph[x].append((y, l))
	graph[y].append((x, l))
if k == 0 or k == n:
	print(-1)
	exit()
if k > 0 and k < n:
	myset = set(get_array())
	mini = 10 ** 9 + 7
	for i in myset:
		for j in graph[i]:
			if j[0] not in myset:
				if j[1] < mini:
					mini = j[1]
	if mini == 10 ** 9 + 7:
		print(-1)
	else:
		print(mini)


try:
	while True:
		(n, m, k) = map(int, input().split())
		edges = [tuple(map(int, input().split())) for i in range(m)]
		if k == 0:
			print(-1)
		else:
			bachery = [False] * n
			for x in map(int, input().split()):
				bachery[x - 1] = True
			result = 10000000000.0
			for (u, v, length) in edges:
				u -= 1
				v -= 1
				if bachery[u]:
					if not bachery[v]:
						result = min(result, length)
				elif bachery[v] and (not bachery[u]):
					result = min(result, length)
			if result > 5000000000.0:
				print(-1)
			else:
				print(result)
except EOFError:
	pass


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	(n, m, k) = map(int, input().split())
	graph = defaultdict(list)
	for i in range(m):
		(u, v, w) = map(int, input().split())
		graph[u].append([v, w])
		graph[v].append([u, w])
	if k == 0:
		print(-1)
	else:
		storage = list(map(int, input().split()))
		myMap = defaultdict(int)
		for val in storage:
			myMap[val] = 1
		ans = float('inf')
		for i in range(1, n + 1):
			size = len(graph[i])
			if myMap[i] and size > 0:
				for j in range(size):
					if myMap[graph[i][j][0]] == 0 and graph[i][j][1] < ans:
						ans = graph[i][j][1]
		if ans != float('inf'):
			print(ans)
		else:
			print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
(n, m, k) = map(int, input().split())
if not k % n:
	print(-1)
	sys.exit()
E = tuple((map(int, input().split()) for _ in range(m)))
F = n * [False]
for a in map(int, input().split()):
	F[a - 1] = True
m = INF = 1 << 30
for (u, v, l) in E:
	if F[u - 1] ^ F[v - 1]:
		m = min(m, l)
print(m if INF > m else -1)


(n, m, k) = map(int, input().split())
roads = []
for _ in range(m):
	roads.append(list(map(int, input().split())))
if k == 0:
	print(-1)
	exit()
shops = [0] * (n + 1)
s = list(map(int, input().split()))
for x in s:
	shops[x] = 1
costs = []
for x in roads:
	if shops[x[0]] + shops[x[1]] == 1:
		costs.append(x[2])
if len(costs) > 0:
	print(min(costs))
else:
	print(-1)


(n, m, k) = map(int, input().split())
line = []
for i in range(m):
	(u, v, l) = map(int, input().split())
	line.append((u, v, l))
if k == 0:
	print(-1)
else:
	dic = {}
	a = list(map(int, input().split()))
	for item in a:
		dic[item] = 1
	ans = 100000000000.0
	for i in range(m):
		if dic.get(line[i][0], 0) == 1 and dic.get(line[i][1], 0) == 0:
			ans = min(ans, line[i][2])
		elif dic.get(line[i][0], 0) == 0 and dic.get(line[i][1], 0) == 1:
			ans = min(ans, line[i][2])
	print(-1 if ans == 100000000000.0 else ans)


(n, m, k) = map(int, input().split(' '))
a = [[] for i in range(n)]
for i in range(m):
	(u, v, l) = map(int, input().split(' '))
	a[u - 1].append([v - 1, l])
	a[v - 1].append([u - 1, l])
if k != 0:
	cklad = set(list(map(lambda x: int(x) - 1, input().split(' '))))
	min1 = -1
	for i in cklad:
		for j in range(len(a[i])):
			if a[i][j][0] not in cklad:
				if min1 > a[i][j][1] or min1 == -1:
					min1 = a[i][j][1]
	print(min1)
else:
	print(-1)


(n, m, k) = map(int, input().split())
if k == 0:
	print(-1)
else:
	paths = {}
	for i in range(m):
		(u, v, l) = map(int, input().split())
		if u not in paths:
			paths[u] = {}
			paths[u][v] = l
		elif v in paths[u]:
			if l < paths[u][v]:
				paths[u][v] = l
		else:
			paths[u][v] = l
		if v not in paths:
			paths[v] = {}
			paths[v][u] = l
		elif u in paths[v]:
			if l < paths[v][u]:
				paths[v][u] = l
		else:
			paths[v][u] = l
	flours = set(map(int, input().split()))
	inf = float('inf')
	result = inf
	for flours_ele in flours:
		if flours_ele in paths:
			for paths_ele in paths[flours_ele]:
				if paths_ele not in flours:
					result = min(result, paths[flours_ele][paths_ele])
					if result == 1:
						print(1)
						exit()
	print(result if result != inf else -1)


(n, m, k) = map(int, input().split())
weight = dict()
w = [set() for i in range(n + 1)]
sklad = set()
INF = 10 ** 9 + 5
for i in range(1, m + 1):
	(v, u, l) = map(int, input().split())
	if u not in w[v]:
		w[v].add(u)
		w[u].add(v)
		weight[u, v] = l
		weight[v, u] = l
	elif l < weight[u, v]:
		weight[u, v] = l
		weight[v, u] = l
if k > 0:
	sklad = set(map(int, input().split()))
dist = INF
for v in sklad:
	for u in w[v]:
		if u not in sklad and weight[u, v] < dist:
			dist = weight[u, v]
if dist == INF:
	print(-1)
else:
	print(dist)


import sys
input = sys.stdin.readline
(x, y, z) = map(int, input().split())
dict1 = {}
for _ in range(y):
	(a, b, c) = map(int, input().split())
	if a in dict1.keys():
		dict1[a].append([b, c])
	else:
		dict1[a] = [[b, c]]
	if b in dict1.keys():
		dict1[b].append([a, c])
	else:
		dict1[b] = [[a, c]]
ans = 1e+18
if z:
	(*li,) = map(int, input().split())
	li = set(li)
	for i in dict1.keys():
		for j in dict1[i]:
			if i in li and j[0] in li:
				continue
			elif i in li or j[0] in li:
				ans = min(ans, j[1])
print(-1 if ans == 1e+18 else ans)


(n, m, k) = map(int, input().split())
if k:
	(G, d) = ({i: set() for i in range(1, n + 1)}, {})
	for _ in range(m):
		(u, v, l) = map(int, input().split())
		if v in G[u]:
			if d[u, v] > l:
				d[u, v] = d[v, u] = l
		else:
			G[u].add(v)
			G[v].add(u)
			d[u, v] = d[v, u] = l
	(storages, min_price) = (set(map(int, input().split())), 1000000001)
	for storage in storages:
		for city in G[storage]:
			if city not in storages:
				min_price = min(min_price, d[city, storage])
	print((min_price, -1)[min_price > 1000000000])
else:
	print(-1)


(n, m, k) = [int(x) for x in input().split()]
i = 0
mp = dict()
while i < m:
	(a, b, c) = [int(x) for x in input().split()]
	if (a, b) in mp:
		if mp[a, b] > c:
			mp[a, b] = c
	else:
		mp[a, b] = c
	i += 1
if k != 0:
	storage = {int(x) for x in input().split()}
if k == 0:
	print(-1)
	quit()
minv = int(9999999999)
for x in mp.keys():
	if x[0] in storage and x[1] not in storage or (x[0] not in storage and x[1] in storage):
		if mp[x] < minv:
			minv = mp[x]
if minv == 9999999999:
	print(-1)
else:
	print(minv)
quit()


[n, m, k] = list(map(int, input().split()))
edges = [[] for i in range(n + 1)]
for i in range(m):
	[u, v, l] = list(map(int, input().split()))
	edges[u].append([v, l])
	edges[v].append([u, l])
res = 1 << 31
if k > 0:
	valid = [1 for i in range(n + 1)]
	valid[0] = 0
	a = list(map(int, input().split()))
	for x in a:
		valid[x] = 0
	for x in a:
		for e in edges[x]:
			if valid[e[0]] == 1:
				res = min(res, e[1])
if res == 1 << 31:
	print('-1')
else:
	print(res)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, m, k) = value()
a = []
d = {i: (-1, inf) for i in range(1, n + 1)}
for i in range(m):
	a.append(value())
store = set(array())
ans = inf
for i in a:
	(s, d, l) = i
	if s in store and d not in store or (s not in store and d in store):
		ans = min(ans, l)
if ans != inf:
	print(ans)
else:
	print(-1)


class CodeforcesTask707BSolution:

	def __init__(self):
		self.result = ''
		self.n_m_k = []
		self.roads = []
		self.storages = []

	def read_input(self):
		self.n_m_k = [int(x) for x in input().split(' ')]
		for x in range(self.n_m_k[1]):
			self.roads.append([int(y) for y in input().split(' ')])
		if self.n_m_k[2]:
			self.storages = [int(x) for x in input().split(' ')]

	def process_task(self):
		graph = [[] for x in range(self.n_m_k[0])]
		for road in self.roads:
			graph[road[0] - 1].append((road[1], road[2]))
			graph[road[1] - 1].append((road[0], road[2]))
		bakeries = {}
		store_locs = set(self.storages)
		for store in self.storages:
			for loc in graph[store - 1]:
				if loc[0] not in store_locs:
					if loc[0] in bakeries:
						bakeries[loc[0]] = min(bakeries[loc[0]], loc[1])
					else:
						bakeries[loc[0]] = loc[1]
		mn = 10 ** 10
		if len(bakeries):
			for (key, value) in bakeries.items():
				mn = min(mn, value)
		else:
			mn = -1
		self.result = str(mn)

	def get_result(self):
		return self.result
Solution = CodeforcesTask707BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, m, k) = map(int, input().split())
roads = []
flagstores = [0] * n
mi = 10 ** 9 + 1
for i in range(m):
	(x, y, l) = map(int, input().split())
	roads.append((x, y, l))
if k > 0:
	stores = list(map(int, input().split()))
	for i in range(k):
		flagstores[stores[i] - 1] = 1
	for i in range(m):
		if flagstores[roads[i][0] - 1] == 1 and flagstores[roads[i][1] - 1] == 0 or (flagstores[roads[i][1] - 1] == 1 and flagstores[roads[i][0] - 1] == 0):
			mi = min(mi, roads[i][2])
	if mi > 10 ** 9:
		print(-1)
	else:
		print(mi)
else:
	print(-1)


import sys

def bakery():
	(n, m, k) = map(int, input().split())
	lst = list()
	for i in range(m):
		(u, v, l) = map(int, input().split())
		lst.append([u - 1, v - 1, l])
	if k > 0:
		storage = [0 for i in range(n)]
		a = input().split()
		for i in range(k):
			storage[int(a[i]) - 1] = 1
		ans = sys.maxsize
		for i in range(m):
			if storage[lst[i][0]] == 0 and storage[lst[i][1]] == 1:
				ans = min(ans, lst[i][2])
			elif storage[lst[i][0]] == 1 and storage[lst[i][1]] == 0:
				ans = min(ans, lst[i][2])
		if ans < sys.maxsize:
			print(ans)
		else:
			print(-1)
		return
	else:
		print(-1)
		return
bakery()


import sys
import heapq

def add_edge(edges, a, b, c):
	edges.append((a, b, c))

def read_graph():
	(n, m, k) = map(int, next(sys.stdin).split())
	edges = []
	for _ in range(m):
		(a, b, c) = map(int, next(sys.stdin).split())
		add_edge(edges, a, b, c)
		add_edge(edges, b, a, c)
	stores = set(map(int, next(sys.stdin).split()) if k > 0 else [])
	return (edges, stores)

def solve(edges, stores):
	best = None
	for (a, b, c) in edges:
		if a in stores and b not in stores or (b in stores and a not in stores):
			if best is None or c < best:
				best = c
	return best
(edges, stores) = read_graph()
ans = solve(edges, stores)
print(ans or -1)


(n, m, k) = map(int, input().split())
if k == 0:
	print(-1)
	exit()
Edges = []
for _ in range(m):
	Edges.append(tuple(map(int, input().split())))
K = set(map(int, input().split()))
minimum = -1
for e in Edges:
	if (e[0] in K) ^ (e[1] in K):
		if minimum == -1:
			minimum = e[2]
		else:
			minimum = min(minimum, e[2])
print(minimum)


(n, m, k) = map(int, input().split())
d = []
for i in range(m):
	(u, v, l) = map(int, input().split())
	d.append((u, v, l))
if k == 0:
	print(-1)
else:
	s = set(map(int, input().split()))
	mn = INF = 211631165165151561
	for (u, v, l) in d:
		if u not in s and v in s or (u in s and v not in s):
			mn = min(mn, l)
	if mn == INF:
		print(-1)
	else:
		print(mn)


def s():
	[n, m, k] = list(map(int, input().split()))
	G = dict()
	for _ in range(m):
		t = list(map(int, input().split()))
		if t[0] > t[1]:
			(t[0], t[1]) = (t[1], t[0])
		if (t[0], t[1]) in G:
			G[t[0], t[1]] = min(G[t[0], t[1]], t[2])
		else:
			G[t[0], t[1]] = t[2]
	a = set(map(int, input().split() if k else ''))
	r = 1000000000.0 + 1
	for (k, v) in G.items():
		s = (k[0] in a) + (k[1] in a)
		if s == 1:
			r = min(r, v)
	print(-1 if r == 1000000000.0 + 1 else r)
s()


class graph(object):

	def __init__(self, n):
		self.cities = {i: 1 for i in range(1, n + 1)}
		self.roads = []

	def addroad(self, u, v, l):
		self.roads.append((min(u, v), max(u, v), l))

	def isstorage(self, a):
		self.cities[a] = 0
(n, m, k) = input().split()
town = graph(int(n))
for road in range(int(m)):
	(u, v, l) = input().split()
	town.addroad(int(u), int(v), int(l))
if int(k) != 0:
	for a in input().split():
		town.isstorage(int(a))
	distance = 1000000001
	for road in town.roads:
		if town.cities[road[0]] + town.cities[road[1]] == 1:
			distance = min(distance, road[2])
	if distance == 1000000001:
		print(-1)
	else:
		print(distance)
else:
	print(-1)


(n, m, k) = list(map(int, input().split()))
uvl = [list(map(int, input().split())) for i in range(m)]
if k == 0:
	print('-1')
else:
	ai = list(map(int, input().split()))
	ai.sort()
	ans = 1000000001

	def bf(x):
		l = 0
		r = k - 1
		while l < r:
			mid = (l + r) // 2
			if ai[mid] < x:
				l = mid + 1
			else:
				r = mid
		if ai[r] == x:
			return 1
		else:
			return 0
	for i in range(m):
		if bf(uvl[i][0]) != bf(uvl[i][1]):
			ans = min(ans, uvl[i][2])
	if ans == 1000000001:
		print('-1')
	else:
		print(ans)


def main():
	(n, m, k) = map(int, input().split())
	graph = {}
	for i in range(1, n + 1):
		graph[i] = []
	for __ in range(m):
		(u, v, l) = map(int, input().split())
		graph[u].append((v, l))
		graph[v].append((u, l))
	if k <= 0:
		print(-1)
	else:
		b = list(map(int, input().split()))
		is_storage = [False] * n
		for i in b:
			is_storage[i - 1] = True
		mini_cost = -1
		for i in b:
			if i in graph:
				for j in graph[i]:
					if not is_storage[j[0] - 1]:
						if mini_cost == -1:
							mini_cost = j[1]
						elif mini_cost > j[1]:
							mini_cost = j[1]
		print(mini_cost)
main()


def solve():
	(n, m, k) = map(int, input().split())
	r = {}
	for _ in range(m):
		(u, v, l) = map(int, input().split())
		if u not in r:
			r[u] = []
		if v not in r:
			r[v] = []
		r[u].append((v, l))
		r[v].append((u, l))
	a = set()
	s = [False] * (n + 1)
	if k > 0:
		a = set(map(int, input().split()))
	for a_ in a:
		s[a_] = True
	ans = float('inf')
	for a_ in a:
		if a_ not in r:
			continue
		for t in r[a_]:
			if s[t[0]]:
				continue
			ans = min(ans, t[1])
	print(-1 if ans == float('inf') else ans)

def main():
	solve()
main()


(n, m, k) = map(int, input().split())
pek = [0] * (n + 1)
edges = []
for i in range(m):
	edges.append(list(map(int, input().split())))
if k != 0:
	Pek = map(int, input().split())
	for p in Pek:
		pek[p] = 1
ans = 10 ** 9 + 1
for edge in edges:
	if pek[edge[0]] ^ pek[edge[1]]:
		ans = min(ans, edge[2])
if ans == 10 ** 9 + 1:
	print(-1)
else:
	print(ans)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, m, k) = int_array()
graph = [[] for _ in range(n + 1)]
dick = {}
for _ in range(m):
	(x, y, l) = int_array()
	graph[x].append(y)
	graph[y].append(x)
	dick[min(x, y), max(x, y)] = min(dick.get((min(x, y), max(x, y)), INF), l)
warehouse = set(int_array())
ans = INF
for i in warehouse:
	for j in graph[i]:
		if j not in warehouse:
			tup = (min(i, j), max(i, j))
			ans = min(ans, dick[tup])
if ans == INF:
	print(-1)
else:
	print(ans)


(n, m, k) = map(int, input().split())
if k == 0:
	print(-1)
	quit()
edge = []
for _ in range(m):
	(u, v, l) = map(int, input().split())
	edge.append((u, v, l))
a = list(map(int, input().split()))
tr = [True] * (n + 1)
for i in a:
	tr[i] = False
ans = float('+inf')
for i in edge:
	(u, v, l) = i
	if tr[u] ^ tr[v]:
		ans = min(ans, l)
if ans == float('+inf'):
	print('-1')
else:
	print(ans)


from sys import stdin, stdout
import heapq as hq
(n, m, k) = list(map(lambda i: int(i), stdin.readline().rstrip().split()))
mark = [False] * (n + 5)
g = [[] for i in range(n)]
for i in range(m):
	(u, v, l) = list(map(lambda i: int(i), stdin.readline().rstrip().split()))
	u -= 1
	v -= 1
	g[u].append((v, l))
	g[v].append((u, l))
if k > 0:
	l = list(map(lambda i: int(i), stdin.readline().rstrip().split()))
	for i in l:
		mark[i - 1] = True
	best = float('inf')
	for i in range(n):
		if mark[i]:
			for j in g[i]:
				if not mark[j[0]]:
					if j[1] < best:
						best = j[1]
	if best == float('inf'):
		stdout.write('-1')
	else:
		stdout.write(str(best))
else:
	stdout.write('-1')


def update_min(v):
	global min_
	for (u, w) in graph[v].items():
		if not is_whouse[u]:
			min_ = min(min_, w)
min_ = 10000000000000000
(n, m, k) = list(map(int, input().split()))
graph = [dict() for i in range(n)]
for i in range(m):
	(u, v, l) = list(map(int, input().split()))
	u -= 1
	v -= 1
	if v in graph[u].keys():
		graph[u][v] = min(l, graph[u][v])
	else:
		graph[u][v] = l
	if u in graph[v].keys():
		graph[v][u] = min(l, graph[v][u])
	else:
		graph[v][u] = l
if k:
	whouses = list(map(int, input().split()))
	is_whouse = [False for i in range(n)]
	for w in whouses:
		is_whouse[w - 1] = True
	for w in whouses:
		update_min(w - 1)
	if min_ == 10000000000000000:
		print(-1)
	else:
		print(min_)
else:
	print(-1)


(n, m, k) = list(map(int, input().split()))
edg = []
for _ in range(m):
	(u, v, d) = list(map(int, input().split()))
	edg.append((u, v, d))
if k == 0:
	print(-1)
	exit(0)
aa = set(map(int, input().split()))
INF = 2000000000
res = INF
for e in edg:
	(u, v, d) = e
	if (u in aa) ^ (v in aa):
		res = min(res, d)
if res == INF:
	print(-1)
else:
	print(res)


import sys
sys.setrecursionlimit(20000)
from collections import Counter
from math import ceil, floor, factorial, fsum, isinf, exp, log, log10, log2, isfinite
from itertools import product

def getlist(tcast):
	return [tcast(x) for x in input().strip().split(' ')]

def getval(tcast):
	return tcast(input().strip())

def getmatrix(r, tcast):
	mat = []
	for i in range(r):
		mat.append(getlist(tcast))
	return mat

def isodd(n):
	return n & 1

def numdigits(n):
	return len(str(n)) - (1 if n < 0 else 0)

def primesupto(n):
	isp = [True] * (n + 1)
	(isp[0], isp[1]) = (False, False)
	for (i, x) in enumerate(isp):
		if x:
			mults = i * i
			while mults <= n:
				isp[mults] = False
				mults += i
	return isp

def maxarrays(a, b):
	return [max(x, y) for (x, y) in zip(a, b)]
(nv, ne, ns) = getlist(int)
if ns == 0 or ne == 0:
	print(-1)
else:
	edges = []
	for i in range(ne):
		(start, end, weight) = getlist(int)
		edges.append((start, end, weight))
	starts = getlist(int)
	checkstart = set(starts)
	best = 100000000000000000
	cur = 0
	for edge in edges:
		(a, b) = (edge[0], edge[1])
		if a in checkstart and b not in checkstart or (b in checkstart and a not in checkstart):
			best = min(best, edge[2])
	print(-1 if best == 100000000000000000 else best)


import sys

def get_ints():
	return map(int, sys.stdin.readline().split())
(n, m, k) = get_ints()
t = [list(get_ints()) for _ in range(m)]
a = set(get_ints()) if k else []
x = [l for (u, v, l) in t if (u in a) ^ (v in a)]
print(min(x) if x else -1)


import sys
input = lambda : sys.stdin.readline().rstrip()
(n, m, k) = [int(i) for i in input().split()]
g = [[] for i in range(n)]
for i in range(m):
	(x, y, z) = [int(i) - 1 for i in input().split()]
	g[x].append([y, z + 1])
	g[y].append([x, z + 1])
a = [int(i) - 1 for i in input().split()]
st = set(a)
ans = []
for i in a:
	for j in g[i]:
		if j[0] not in st:
			ans.append(j[1])
if ans:
	print(min(ans))
else:
	print(-1)


(n, m, k) = map(int, input().split())
eg = []
for (x, y, c) in [map(int, input().split()) for _ in range(m)]:
	eg.append([x - 1, y - 1, c])
	eg.append([y - 1, x - 1, c])
vis = [0 for _ in range(n)]
if k > 0:
	klist = list(map(int, input().split()))
	for i in klist:
		vis[i - 1] = 1
minv = 1000000000.0 + 100
for i in eg:
	if minv > i[2] and (vis[i[0]] == 0 and vis[i[1]] or (vis[i[0]] and vis[i[1]] == 0)):
		minv = i[2]
print(minv) if minv != 1000000000.0 + 100 else print(-1)


def main():
	(n, m, k) = map(int, input().split())
	graph = [[] for i in range(n + 1)]
	for i in range(m):
		(u, v, l) = map(int, input().split())
		graph[u].append((v, l))
		graph[v].append((u, l))
	if k == 0:
		print(-1)
		return
	a = list(map(int, input().split()))
	check = [True for i in range(n + 1)]
	for x in a:
		check[x] = False
	ans = 10 ** 10
	for x in a:
		if graph[x] != []:
			for y in graph[x]:
				if check[y[0]]:
					ans = min(ans, y[1])
	if ans == 10 ** 10:
		ans = -1
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, m, k) = map(int, input().split())
f = []
for j in range(m):
	f.append(list(map(int, input().split())))
if k == 0:
	print('-1')
	exit()
else:
	arr = set(map(int, input().split()))
ans = []
for i in f:
	[u, v, l] = i
	if (u in arr) ^ (v in arr):
		ans.append(l)
if ans == []:
	print('-1')
else:
	print(min(ans))


(n, m, k) = list(map(int, input().split()))
graph = {}
vertices = set()
ans = -1
floor = [False] * (n + 1)
for i in range(m):
	(u, v, l) = list(map(int, input().split()))
	if u not in vertices:
		vertices.update([u])
		graph[u] = []
	if v not in vertices:
		vertices.update([v])
		graph[v] = []
	graph[u].append([v, l])
	graph[v].append([u, l])
if k != 0:
	A = []
	for i in input().split():
		floor[int(i)] = True
		A.append(int(i))
	valids = []
	for x in A:
		if x in vertices:
			for nb in graph[x]:
				if not floor[nb[0]]:
					valids.append(nb[1])
	if len(valids) > 0:
		ans = min(valids)
print(ans)


from collections import defaultdict

class Graph:

	def __init__(self):
		self.dict = defaultdict(lambda : {})

def main():
	g = Graph()
	(n, m, k) = (int(i) for i in input().split())
	minimum = -1
	if k > 0:
		for i in range(m):
			(u, v, k) = (int(i) for i in input().split())
			if u not in g.dict[v] or k < g.dict[v][u]:
				g.dict[v][u] = k
				g.dict[u][v] = k
		cities_with_storage = set([int(i) for i in input().split()])
		for city in cities_with_storage:
			for neighbor in g.dict[city].keys():
				cost = g.dict[city][neighbor]
				if neighbor not in cities_with_storage and (minimum == -1 or cost < minimum):
					minimum = cost
	print(minimum)
main()


from collections import defaultdict
(n, m, k) = map(int, input().split())
graph = defaultdict(list)
for i in range(m):
	(u, v, w) = map(int, input().split())
	graph[u].append([v, w])
	graph[v].append([u, w])
if k == 0:
	print(-1)
else:
	storage = list(map(int, input().split()))
	myMap = defaultdict(int)
	for val in storage:
		myMap[val] = 1
	ans = float('inf')
	for i in range(1, n + 1):
		size = len(graph[i])
		if myMap[i] and size > 0:
			for j in range(size):
				if myMap[graph[i][j][0]] == 0 and graph[i][j][1] < ans:
					ans = graph[i][j][1]
	if ans != float('inf'):
		print(ans)
	else:
		print(-1)


import sys
(n, m, k) = map(int, input().split())
roads = [input().split() for _ in range(m)]
storageCitys = {}
if k > 0:
	storageCitys = set(input().split())
minPay = sys.maxsize
for road in roads:
	aCityOfThisRoad = road[0]
	anotherCityOfThisRoad = road[1]
	if aCityOfThisRoad in storageCitys and anotherCityOfThisRoad not in storageCitys or (aCityOfThisRoad not in storageCitys and anotherCityOfThisRoad in storageCitys):
		lengthOfThisRoad = int(road[2])
		if lengthOfThisRoad < minPay:
			minPay = lengthOfThisRoad
if minPay == sys.maxsize:
	print('-1')
else:
	print(minPay)


(n, m, k) = map(int, input().split())
edge = []
for i in range(m):
	(a, b, c) = map(int, input().split())
	edge.append([a, b, c])
if k != 0:
	flour = [0] * (n + 1)
	for i in list(map(int, input().split())):
		flour[i] = 1
	ans = 10 ** 18
	for e in edge:
		if flour[e[0]] != flour[e[1]]:
			ans = min(ans, e[2])
	if ans == 10 ** 18:
		print(-1)
	else:
		print(ans)
else:
	print(-1)


f = lambda : map(int, input().split())
(n, m, k) = f()
t = [list(f()) for q in range(m)]
a = set(f()) if k else []
x = [l for (u, v, l) in t if (u in a) ^ (v in a)]
print(min(x) if x else -1)


(n, m, k) = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
	(s, v, w) = map(int, input().split())
	(s, v) = (s - 1, v - 1)
	g[s].append((v, w))
	g[v].append((s, w))
if not k:
	print(-1)
	exit()
stores = {num - 1 for num in map(int, input().split())}
minw = float('inf')
for s in stores:
	for (v, w) in g[s]:
		if v not in stores:
			minw = min(minw, w)
print(minw if minw != float('inf') else -1)


(n, m, k) = map(int, input().split())
g = {}
for _ in range(m):
	(u, v, l) = map(int, input().split())
	if not u - 1 in g:
		g[u - 1] = []
	if not v - 1 in g:
		g[v - 1] = []
	g[u - 1].append((v - 1, l))
	g[v - 1].append((u - 1, l))
storages = [] if k == 0 else list(map(lambda x: int(x) - 1, input().split()))
isstor = [False for _ in range(n)]
for s in storages:
	isstor[s] = True
best = float('inf')
for s in storages:
	if not s in g:
		continue
	for ne in g[s]:
		if isstor[ne[0]]:
			continue
		else:
			best = min(best, ne[1])
print(-1 if best == float('inf') else best)


(n, m, k) = (int(i) for i in input().split())
r = []
for i in range(m):
	(u, v, p) = (int(i) for i in input().split())
	r += [(p, u, v)]
if k == 0:
	print(-1)
	exit(0)
else:
	s = list(map(int, input().split()))
	sklad = [False] * n
	for i in range(len(s)):
		sklad[s[i] - 1] = True
	ans = 10 ** 10
	for i in range(len(r)):
		if sklad[r[i][1] - 1] != sklad[r[i][2] - 1]:
			ans = min(ans, r[i][0])
if ans == 10 ** 10:
	print(-1)
else:
	print(ans)


(vert, edge, storage) = map(int, input().split())
G = {x: [] for x in range(1, vert + 1)}
for i in range(edge):
	(u, v, c) = map(int, input().split())
	G[u].append((v, c))
	G[v].append((u, c))
if storage:
	stor = set(map(int, input().split()))
	ans = 10 ** 12
	for s in stor:
		for (v, c) in G[s]:
			if v not in stor:
				ans = min(ans, c)
	print(-1 if ans == 10 ** 12 else ans)
else:
	print(-1)


(n, m, k) = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(m)]
storages = [False] * (n + 1)
if k:
	for city in map(int, input().split()):
		storages[city] = True
res = float('inf')
for edge in edges:
	if storages[edge[0]] != storages[edge[1]]:
		res = min(res, edge[2])
if res == float('inf'):
	res = -1
print(res)


const = 1000000000001

def minCost(d, valid):
	minimum = const
	for x in d:
		(a, b) = (x[0], x[1])
		if valid[a] == -1 and valid[b] == 0 or (valid[a] == 0 and valid[b] == -1):
			if minimum > d[x]:
				minimum = d[x]
	if minimum == const:
		return -1
	return minimum
(n, m, k) = map(int, input().split())
d = {}
for i in range(m):
	(u, v, w) = map(int, input().split())
	if (u, v) in d:
		if w < d[u, v]:
			d[u, v] = w
	else:
		d[u, v] = w
valid = [0] * (n + 1)
if k != 0:
	storage = list(map(int, input().split()))
	for x in storage:
		valid[x] = -1
print(minCost(d, valid))


(N, M, K) = list(map(int, input().split()))
ftcs = []
for m in range(M):
	(f, t, c) = list(map(int, input().split()))
	ftcs.append((f, t, c))
if K != 0:
	storages = list(map(int, input().split()))
else:
	storages = []
storages_s = set(storages)
mn = 1e+20
for (f, t, c) in ftcs:
	if f in storages_s and t not in storages_s or (t in storages_s and f not in storages_s):
		mn = min(mn, c)
if mn == 1e+20:
	print(-1)
else:
	print(mn)


(n, m, k) = map(int, input().split())
roads = [input().split() for i in range(m)]
max_dist = 10 ** 9 + 1
minDis = max_dist
storage = set()
if k != 0:
	storage.update(input().split())
	for r in roads:
		if (r[0] in storage) ^ (r[1] in storage):
			minDis = min(minDis, int(r[2]))
if minDis < max_dist:
	print(minDis)
else:
	print(-1)


inp = lambda : [*map(int, input().split())]
(n, m, k) = inp()
lines = [inp() for i in range(m)]
storage = [False] * (n + 1)
if k != 0:
	for i in inp():
		storage[i] = True
ans = -1
for i in lines:
	if storage[i[0]] or storage[i[1]]:
		if not (storage[i[0]] and storage[i[1]]):
			ans = min(ans, i[2]) if ans >= 0 else i[2]
print(ans)


import sys
(n, m, k) = [int(x) for x in input().split()]
MAXDIST = 10 ** 9 + 1
if n == k or k == 0:
	print(-1)
	sys.exit()
adj = [[] for i in range(n)]
for i in range(m):
	(a, b, c) = [int(x) for x in input().split()]
	a -= 1
	b -= 1
	adj[a].append((b, c))
	adj[b].append((a, c))
lst = [int(x) - 1 for x in input().split()]
in_lst = [False] * n
for v in lst:
	in_lst[v] = True
ans = MAXDIST
for v in lst:
	for elem in adj[v]:
		if in_lst[elem[0]]:
			continue
		if ans > elem[1]:
			ans = elem[1]
if ans == MAXDIST:
	print(-1)
else:
	print(ans)


(n, m, k) = input().split()
n = int(n)
m = int(m)
k = int(k)
s = list()
flag = []
for i in range(n + 1):
	flag.append(False)
for i in range(m):
	t = input().split()
	r = list()
	for gg in t:
		r.append(int(gg))
	s.append(r)
if k:
	t = input().split()
	for gg in t:
		flag[int(gg)] = True
infs = 1061109567
ans = infs
for tt in s:
	if flag[tt[0]] != flag[tt[1]]:
		if ans > tt[2]:
			ans = tt[2]
if ans == infs:
	print('-1')
else:
	print(ans)


import sys
(n_cities, n_roads, n_flours) = [int(n) for n in input().split()]
if n_flours == 0:
	print(-1)
	sys.exit()
roads = []
for _ in range(n_roads):
	r = [int(n) for n in input().split()]
	roads.append(r)
flours = [False] * (n_cities + 1)
for n in input().split():
	f = int(n)
	flours[f] = True
minimum = sys.maxsize
for r in roads:
	if flours[r[0]] and (not flours[r[1]]) or (flours[r[1]] and (not flours[r[0]])):
		minimum = min(minimum, r[2])
print(minimum if minimum != sys.maxsize else -1)


import math
import bisect
import sys
from collections import OrderedDict
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
(N, M, K) = invr()
adj = [[] for i in range(N)]
for m in range(M):
	(u, v, l) = invr()
	adj[u - 1].append((v - 1, l))
	adj[v - 1].append((u - 1, l))
if K == 0 or K == N:
	print(-1)
elif K > 0:
	A = set(inlt())
	B = set([i + 1 for i in range(N)])
	Z = B - A
	out = 10 ** 10
	for c in Z:
		for d in adj[c - 1]:
			if d[0] + 1 in A:
				out = min(out, d[1])
	if out == 10 ** 10:
		print(-1)
	else:
		print(out)


[n, m, k] = [int(x) for x in input().split()]
a = []
for i in range(0, m):
	a.append([int(x) for x in input().split()])
b = [0 for x in range(0, n + 1)]
if k:
	for x in input().split():
		b[int(x)] = 1
else:
	print(-1)
	exit(0)
minc = 1000000001
for i in range(0, m):
	if b[a[i][0]] == 0 and b[a[i][1]] == 1 or (b[a[i][0]] == 1 and b[a[i][1]] == 0):
		if minc > a[i][2]:
			minc = a[i][2]
if minc != 1000000001:
	print(minc)
else:
	print(-1)


(n, m, k) = map(int, input().split())
s = [False for i in range(n + 1)]
d = [[] for i in range(n + 1)]
for i in range(m):
	(u, v, l) = map(int, input().split())
	u -= 1
	v -= 1
	d[u].append([v, l])
	d[v].append([u, l])
a = []
if k > 0:
	a = list(map(int, input().split()))
for i in range(k):
	s[a[i] - 1] = True
c = 10 ** 9 + 1
for i in range(k):
	for (j, l) in d[a[i] - 1]:
		if s[j] == False:
			c = min(c, l)
if c == 10 ** 9 + 1:
	print(-1)
else:
	print(c)


line1 = input().split()
n = int(line1[0])
m = int(line1[1])
k = int(line1[2])
roads = []
for i in range(m):
	line = input().split()
	(line[0], line[1], line[2]) = (int(line[0]), int(line[1]), int(line[2]))
	roads.append(line)
cities = {}
for i in range(n):
	cities[i + 1] = False
if k > 0:
	line = input().split()
	for c in line:
		cities[int(c)] = True
best = -1
for road in roads:
	u = road[0]
	v = road[1]
	l = road[2]
	if cities[u] == (not cities[v]):
		if best == -1:
			best = l
		else:
			best = min(best, l)
print(best)


from sys import stdin
input_1 = stdin.readline().split()
cities = int(input_1[0])
roads = int(input_1[1])
warehouses = int(input_1[2])
graph = [dict() for _ in range(cities)]
if warehouses == 0 or warehouses >= cities:
	print('-1')
else:
	for i in range(roads):
		new_road = stdin.readline().split()
		city_1 = int(new_road[0])
		city_2 = new_road[1]
		length = int(new_road[2])
		if graph[city_1 - 1].setdefault(city_2, length) > length:
			graph[city_1 - 1][city_2] = length
		(city_1, city_2) = (int(city_2), str(city_1))
		if graph[city_1 - 1].setdefault(city_2, length) > length:
			graph[city_1 - 1][city_2] = length
	warehouse_cities = [int(x) for x in stdin.readline().split()]
	shortest_road = None
	for warehouse_city in warehouse_cities:
		for (city, road) in graph[warehouse_city - 1].items():
			if int(city) not in warehouse_cities and (not shortest_road or road < shortest_road):
				shortest_road = road
	if shortest_road:
		print(shortest_road)
	else:
		print('-1')


def main():
	(n, m, k) = map(int, input().split(' '))
	if k == 0:
		print('-1')
		exit()
	ip = []
	for i in range(m):
		ip.append(list(map(int, input().split(' '))))
	boolMarked = [False] * (n + 1)
	ipK = [int(item) for item in input().split(' ')]
	for i in ipK:
		boolMarked[i] = True
	minimum = float('inf')
	for i in range(len(ip)):
		if boolMarked[ip[i][0]] and (not boolMarked[ip[i][1]]):
			minimum = min(ip[i][2], minimum)
		elif boolMarked[ip[i][1]] and (not boolMarked[ip[i][0]]):
			minimum = min(ip[i][2], minimum)
	if minimum == float('inf'):
		print('-1')
	else:
		print(minimum)
main()


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
from heapq import *
ip = [line for line in sys.stdin.read().split('\n')]
it = 0
(n, m, k) = map(int, ip[it].split())
it += 1
g = [{} for _ in range(n)]
for _ in range(m):
	(u, v, l) = map(int, ip[it].split())
	it += 1
	u -= 1
	v -= 1
	g[u][v] = min(g[u].get(v, float('inf')), l)
	g[v][u] = min(g[v].get(u, float('inf')), l)
if k == 0:
	print(-1)
	sys.exit(0)
q = []
vis = [False] * n
a = set([int(x) - 1 for x in ip[it].split()])
it += 1
for i in a:
	vis[i] = True
	for nbr in g[i]:
		q.append([g[i][nbr], nbr])
heapify(q)
while q:
	(cost, node) = heappop(q)
	if vis[node]:
		continue
	vis[node] = True
	if node not in a:
		print(cost)
		sys.exit(0)
	for nbr in g[node]:
		if not vis[nbr]:
			heappush(q, [cost + g[node][nbr], nbr])
print(-1)


(n, m, k) = map(int, input().split(' '))
paths = []
answer = -1
for i in range(m):
	paths.append(map(int, input().split(' ')))
if k > 0:
	storage = set(map(int, input().split(' ')))
else:
	storage = []
for path in paths:
	p = list(path)
	if answer == -1:
		if (p[0] in storage) ^ (p[1] in storage):
			answer = p[2]
	elif p[2] < answer:
		if (p[0] in storage) ^ (p[1] in storage):
			answer = min(answer, p[2])
print(answer)


(n, m, k) = input().strip().split()
n = int(n)
m = int(m)
k = int(k)
if k == 0:
	ans = -1
else:
	u = []
	v = []
	l = []
	for i in range(m):
		(a, b, c) = input().strip().split()
		u.append(int(a))
		v.append(int(b))
		l.append(int(c))
	vis = [0 for i in range(n + 1)]
	k = input().strip().split()
	ans = 1000000001
	for (index, item) in enumerate(k):
		vis[int(item)] = 1
	for i in range(m):
		if vis[u[i]] == 1 and vis[v[i]] == 0 or (vis[v[i]] == 1 and vis[u[i]] == 0):
			ans = min(ans, l[i])
	if ans == 1000000001:
		ans = -1
print(ans)


read = lambda : map(int, input().split())
(n, m, k) = read()
g = [list() for i in range(n + 1)]
for i in range(m):
	(u, v, l) = read()
	g[u].append((v, l))
	g[v].append((u, l))
if k > 0:
	p = set(read())
else:
	p = []
f = [0] * (n + 1)
for v in p:
	f[v] = 1
ans = 10 ** 20
for v in range(1, n + 1):
	if f[v]:
		continue
	for (u, l) in g[v]:
		if not f[u]:
			continue
		ans = min(ans, l)
if ans == 10 ** 20:
	ans = -1
print(ans)


import math

def BinarySearch(lys, val):
	first = 0
	last = len(lys) - 1
	index = -1
	while first <= last and index == -1:
		mid = (first + last) // 2
		if lys[mid] == val:
			index = mid
		elif val < lys[mid]:
			last = mid - 1
		else:
			first = mid + 1
	if index == -1:
		return False
	return True

def isPossibleRoad(road, storages):
	if BinarySearch(storages, road[0]) == BinarySearch(storages, road[1]):
		return False
	return True

def problem(n, m, k, roads, storages):
	if k == 0 or k == n:
		return -1
	storages.sort()
	roads.sort(key=lambda x: x[2])
	for r in roads:
		if isPossibleRoad(r, storages):
			return r[2]
	return -1

def asrtEq(testNum, v1, v2):
	print(f'Test {testNum}....... ', end='')
	if v1 == v2:
		print(f'SUCCESS')
		return True
	else:
		print(f'FAIL ({v1} != {v2})')
		return False

def tdd():
	n = 5
	m = 4
	k = 2
	roads = [[1, 2, 5], [1, 2, 3], [2, 3, 4], [1, 4, 10]]
	storages = [1, 5]
	res = problem(n, m, k, roads, storages)
	if not asrtEq(1, res, 3):
		return False
	n = 3
	m = 1
	k = 1
	roads = [[1, 2, 3]]
	storages = [3]
	res = problem(n, m, k, roads, storages)
	if not asrtEq(2, res, -1):
		return False
	n = 6
	m = 7
	k = 4
	roads = [[5, 6, 21], [3, 6, 18], [1, 6, 5], [4, 6, 4], [1, 2, 13], [3, 4, 7], [1, 2, 15]]
	storages = [6, 1, 3, 2]
	res = problem(n, m, k, roads, storages)
	if not asrtEq(3, res, 4):
		return False

def user():
	aux = list(map(int, input().split()))
	n = aux[0]
	m = aux[1]
	k = aux[2]
	roads = []
	for i in range(m):
		aux = list(map(int, input().split()))
		roads.append(aux)
	storages = []
	if k > 0:
		storages = list(map(int, input().split()))
	res = problem(n, m, k, roads, storages)
	print(res)
test = False
if test:
	tdd()
else:
	user()


(n, m, k) = map(int, input().split())

class node:

	def __init__(self, val):
		self.val = val
		self.neighbours = set()
		self.is_storage = False

	def addneigh(self, Nde):
		self.neighbours.add(Nde)

def solvewithstorage(nodeslist, storages):
	min_dist = float('inf')
	min_node = None
	for i in storages:
		neigh = nodeslist[i].neighbours
		for j in neigh:
			if not nodeslist[j[0]].is_storage and j[1] < min_dist:
				min_dist = j[1]
	if min_dist == float('inf'):
		return -1
	else:
		return min_dist

def solvewithcity(nodeslist, storages):
	min_dist = float('inf')
	min_node = None
	useful = [i for i in range(1, n + 1) if nodeslist[i].is_storage == False]
	for i in useful:
		neigh = nodeslist[i].neighbours
		for j in neigh:
			if nodeslist[j[0]].is_storage and j[1] < min_dist:
				min_dist = j[1]
	if min_dist == float('inf'):
		return -1
	else:
		return min_dist
nodeslist = [node(i) for i in range(n + 1)]
for i in range(m):
	(u, v, l) = map(int, input().split())
	nodeslist[u].addneigh((v, l))
	nodeslist[v].addneigh((u, l))
storages = []
if k > 0:
	storages = list(map(int, input().split()))
	for i in storages:
		nodeslist[i].is_storage = True
if len(storages) == 0:
	print(-1)
elif len(storages) > n // 2:
	print(solvewithcity(nodeslist, storages))
else:
	print(solvewithstorage(nodeslist, storages))


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def int_line():
	return [int(zax) for zax in input().split()]
(nodes, edges, storages) = int_line()
neighbors = [[] for i in range(nodes)]
for i in range(edges):
	(a, b, dist) = int_line()
	a -= 1
	b -= 1
	neighbors[a].append((b, dist))
	neighbors[b].append((a, dist))
if storages > 0:
	temp = [int(zax) - 1 for zax in input().split()]
else:
	temp = []
storages = {}
for i in temp:
	storages[i] = True
best = 10 ** 12
for i in storages:
	for j in neighbors[i]:
		dist = j[1]
		if dist < best and j[0] not in storages:
			best = dist
if best == 10 ** 12:
	print(-1)
else:
	print(best)


import sys
import collections
(n, m, k) = list(map(int, str.split(sys.stdin.readline())))
if k == 0:
	print(-1)
else:
	d = collections.defaultdict(set)
	for _ in range(m):
		(u, v, l) = list(map(int, str.split(sys.stdin.readline())))
		d[u].add((v, l))
		d[v].add((u, l))
	aks = set(map(int, str.split(sys.stdin.readline())))
	cheapest = None
	for source in aks:
		for (destination, l) in d[source]:
			if destination not in aks:
				if cheapest is None:
					cheapest = l
				else:
					cheapest = min(cheapest, l)
	print(cheapest or -1)


import sys
(n, m, k) = list(map(int, input().split()))
links = [[int(i) for i in input().split()] for i in range(m)]
if k == 0:
	print(-1)
	return
flour_cities = set((int(i) for i in input().split()))
shortest_path = float('inf')
shortest_path_exists = False
for (u, v, l) in links:
	u_has_flour = u in flour_cities
	v_has_flour = v in flour_cities
	if u_has_flour and (not v_has_flour) or (not u_has_flour and v_has_flour):
		shortest_path_exists = True
		shortest_path = min(l, shortest_path)
if shortest_path_exists:
	print(shortest_path)
else:
	print(-1)


def read_tokens():
	return input().strip().split(' ')

def read_ints():
	return [int(s) for s in read_tokens()]
(n, m, k) = read_ints()
graph = [[] for _ in range(n)]
bank = [False] * n

def add_edge(u, v, l):
	global graph
	graph[u].append((v, l))
	graph[v].append((u, l))
for i in range(m):
	(u, v, l) = read_ints()
	u = u - 1
	v = v - 1
	add_edge(u, v, l)
if k != 0:
	bank_positions = read_ints()
	for idx in bank_positions:
		idx = idx - 1
		bank[idx] = True

def solve():
	ans = 1000000000.0 + 1
	for i in range(n):
		if not bank[i]:
			continue
		for (u, l) in graph[i]:
			if not bank[u]:
				ans = min(ans, l)
	return -1 if ans == 1000000000.0 + 1 else ans
print(solve())


import math

def proB(arr, shop):
	ans = math.inf
	shop = set(shop)
	for i in arr:
		(a, b, l) = (i[0], i[1], i[2])
		if a in shop and b in shop:
			continue
		if a in shop:
			ans = min(ans, l)
		if b in shop:
			ans = min(ans, l)
	if ans == math.inf:
		return -1
	return ans
(n, m, k) = list(map(int, input().split()))
arr = []
for i in range(m):
	arr1 = list(map(int, input().split()))
	arr.append(arr1)
if k == 0:
	print(-1)
else:
	shop = list(map(int, input().split()))
	print(proB(arr, shop))


(n, m, k) = map(int, input().split())
ls = []
for i in range(m):
	(u, v, l) = map(int, input().split())
	ls.append([u - 1, v - 1, l])
if k > 0:
	a = input().split()
	storage = [0 for i in range(n)]
	for i in range(k):
		storage[int(a[i]) - 1] = 1
	ans = 10 ** 9 + 1
	for i in range(m):
		if storage[ls[i][0]] == 1 and storage[ls[i][1]] == 0:
			ans = min(ans, ls[i][2])
		elif storage[ls[i][1]] == 1 and storage[ls[i][0]] == 0:
			ans = min(ans, ls[i][2])
	if ans < 10 ** 9 + 1:
		print(ans)
	else:
		print(-1)
else:
	print(-1)


import math
minimum_path = math.inf
(n, m, k) = [int(i) for i in input().split()]
edges = [None] * m
for i in range(m):
	edges[i] = [int(i) for i in input().split()]
if k == 0 or k == n:
	print(-1)
	exit()
nodes = [0] * n
for i in [int(j) - 1 for j in input().split()]:
	nodes[i] = 1
for i in range(m):
	if nodes[edges[i][0] - 1] != nodes[edges[i][1] - 1]:
		minimum_path = min(minimum_path, edges[i][2])
if minimum_path == math.inf:
	print(-1)
else:
	print(minimum_path)


(n, m, k) = [int(x) for x in input().split()]
distance = {}
edge = {}
for i in range(1, n + 1):
	edge[i] = []
	distance[i] = -1
for i in range(1, m + 1):
	(u, v, l) = [int(x) for x in input().split()]
	edge[u].append((v, {'nei': v, 'dis': l}))
	edge[v].append((u, {'nei': u, 'dis': l}))
if k != 0:
	a = [int(x) for x in input().split()]
	for z in a:
		distance[z] = 0
	for uu in a:
		frontier = [uu]
		while frontier:
			next = []
			for u in frontier:
				for (v, vv) in edge[u]:
					jarak = vv.get('dis')
					if distance[v] == -1:
						distance[v] = jarak + distance[u]
						next.append(v)
					elif jarak + distance[u] < distance[v]:
						next.append(v)
						distance[v] = jarak + distance[u]
			frontier = next
	minim = 1000000000
	cek = False
	for uu in distance:
		if distance[uu] != -1 and distance[uu] != 0:
			minim = min(minim, distance[uu])
			cek = True
	if cek:
		print(minim)
	else:
		print(-1)
else:
	print(-1)


import math
import sys
from collections import defaultdict
from collections import Counter
from collections import deque
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]
INF = 10 ** 18
MOD = 10 ** 9 + 7
G = defaultdict(list)

def addEdge(a, b):
	G[a].append(b)
	G[b].append(a)
(n, m, k) = ilele()
cost = {}
for i in range(m):
	(u, v, d) = ilele()
	cost[u, v] = min(d, cost.get((u, v), 1000000000.0))
	cost[v, u] = min(d, cost.get((v, u), 1000000000.0))
	addEdge(u, v)
if k == 0:
	print(-1)
else:
	A = alele()
	storage = {}
	for i in A:
		storage[i] = 1
	Ans = 10000000000.0
	for i in A:
		for j in G.get(i, []):
			if storage.get(j, -1) == -1:
				Ans = min(Ans, cost.get((i, j), 10000000000.0))
	if Ans == 10000000000.0:
		print(-1)
	else:
		print(Ans)


(n, m, k) = map(int, input().split())
if k == 0:
	print(-1)
	exit()
d = []
res = 10 ** 10
for i in range(n):
	d.append([])
for i in range(m):
	(b, e, l) = map(int, input().split())
	d[b - 1].append((e - 1, l))
	d[e - 1].append((b - 1, l))
pl = list(map(int, input().split()))
st = set()
for i in range(len(pl)):
	st.add(pl[i] - 1)
for i in range(len(d)):
	d1 = i in st
	for j in range(len(d[i])):
		d2 = d[i][j][0] in st
		if d1 and (not d2) or (not d1 and d2):
			if d[i][j][1] < res:
				res = d[i][j][1]
if res == 10 ** 10:
	print(-1)
else:
	print(res)


from collections import Counter as cntr
from math import inf

def cin():
	return map(int, input().split(' '))
(n, m, k) = cin()
l = []
for i in range(m):
	l.append(list(cin()))
if k == 0:
	a = []
else:
	a = set()
	a.update(list(cin()))
final = []
for i in l:
	(u, v, w) = (i[0], i[1], i[2])
	if u in a and v in a:
		continue
	if u in a or v in a:
		final.append(w)
if final:
	print(min(final))
else:
	print(-1)


from operator import itemgetter
(n, m, k) = map(int, input().split())
flag = [0] * (n + 2)
list1 = []
for _ in range(0, m):
	(a, b, c) = map(int, input().split())
	list1.append((a, b, c))
make = False
if k == 0:
	print('-1')
else:
	ar = map(int, input().split())
	for x in ar:
		flag[x] = 1
	for (a, b, c) in sorted(list1, key=itemgetter(2)):
		if flag[a] + flag[b] == 1:
			print(c)
			make = True
			break
	if make is False:
		print('-1')


(n, m, k) = [int(i) for i in input().split()]
graph = [[] for i in range(n + 1)]
s = [False] * (n + 1)
for i in range(m):
	(u, v, l) = [int(i) for i in input().split()]
	graph[u].append((v, l))
	graph[v].append((u, l))
if k != 0:
	a = [int(i) for i in input().split()]
for i in range(k):
	s[a[i]] = True
inf = 1000000000000
best = inf
for i in range(k):
	for (j, l) in graph[a[i]]:
		if not s[j]:
			best = min(best, l)
if best == inf:
	print(-1)
else:
	print(best)


def solve(roads):
	if roads:
		min_way = min(roads)
		return min_way + 1
	return '-1'

def roads_backery2city(backery, all_roads):
	roads = []
	for (u, v, w) in all_roads:
		if backery[u] and (not backery[v]) or (backery[v] and (not backery[u])):
			roads.append(w)
	return roads
(n, m, k) = map(int, input().split())
if k == 0:
	print('-1')
else:
	all_roads = [map(lambda x: int(x) - 1, input().split()) for _ in range(m)]
	backery = [False] * n
	for i in map(lambda x: int(x) - 1, input().split()):
		backery[i] = True
	roads = roads_backery2city(backery, all_roads)
	print(solve(roads))


INFTY = 10 ** 10
(n, m, k) = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
	(u, v, l) = map(int, input().split())
	edge[u - 1].append((v - 1, l))
	edge[v - 1].append((u - 1, l))
store = [False for _ in range(n)]
res = INFTY
if k > 0:
	for a in map(int, input().split()):
		store[a - 1] = True
	for i in range(n):
		if store[i]:
			continue
		for (v, l) in edge[i]:
			if not store[v]:
				continue
			res = min(res, l)
if res < INFTY:
	print(res)
else:
	print(-1)


I = lambda : int(input())
IL = lambda : list(map(int, input().split()))
(n, m, k) = IL()
roads = [IL() for i in range(m)]
roads += [[i[1], i[0], i[2]] for i in roads]
storages = set()
if k:
	storages = set(IL())
bakeries = set(range(1, n + 1)) - storages
prices = [i[2] for i in roads if i[0] in storages and i[1] in bakeries]
print(min(prices) if len(prices) else -1)


import sys

class Road:

	def __init__(self, city1, city2, cost):
		self.city1 = city1
		self.city2 = city2
		self.cost = cost

	def __gt__(self, other):
		return self.cost > other.cost
(num_cities, num_roads, num_storage) = map(int, input().split(' '))
roads = []
for i in range(num_roads):
	(c1, c2, cost) = map(int, input().split(' '))
	roads.append(Road(c1, c2, cost))
roads = sorted(roads)
if not num_storage:
	print(-1)
	sys.exit()
storage = set(map(int, input().split(' ')))
cost = -1
for road in roads:
	if road.city1 in storage:
		if road.city2 not in storage:
			cost = road.cost
			break
	elif road.city2 in storage:
		if road.city1 not in storage:
			cost = road.cost
			break
print(cost)


import sys
(n, m, k) = map(int, input().split())
r = [input().split() for j in range(m)]
(a, v) = (set(), sys.maxsize)
if k:
	a.update(input().split())
for ri in r:
	if (ri[0] in a) ^ (ri[1] in a):
		v = min(v, int(ri[2]))
print(-1 if v == sys.maxsize else v)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
(n, m, k) = map(int, input().split())
p = []
for i in range(m):
	(u, v, l) = map(int, input().split())
	p.append([u, v, l])
a = list(map(int, input().split()))
a = set(a)
ans = 2 ** 40
f = False
for i in range(m):
	if p[i][0] in a and p[i][1] not in a:
		ans = min(ans, p[i][2])
		f = True
	if p[i][1] in a and p[i][0] not in a:
		ans = min(ans, p[i][2])
		f = True
if f:
	print(ans)
else:
	print(-1)


(n, m, k) = [int(x) for x in input().split(' ')]
pairs = []
for i in range(m):
	pairs.append(list(map(int, input().split(' '))))
if not k:
	print(-1)
else:
	store = set(map(int, input().split(' ')))
	ans = 10 ** 9 + 5
	for i in pairs:
		a = i[0] in store
		b = i[1] in store
		if a and (not b) or (not a and b):
			ans = min(ans, i[2])
	print(-1 if ans == 10 ** 9 + 5 else ans)


def find_cheapest_city():
	GUARD_LEN = 1000000001
	(n, m, k) = (int(x) for x in input().split())
	(roads, storages) = (list(), dict())
	for i in range(m):
		road = (int(x) for x in input().split())
		roads.append(road)
	if k == 0:
		return -1
	stores = input().split()
	for st in stores:
		storages[int(st)] = None
	min_len = GUARD_LEN
	for i in range(m):
		(from_city, to_city, length) = roads.pop()
		if from_city in storages and to_city in storages:
			continue
		if from_city not in storages and to_city not in storages:
			continue
		min_len = min(min_len, length)
	if GUARD_LEN == min_len:
		return -1
	return min_len
print(find_cheapest_city())


import math
from collections import deque
import heapq

def main():
	(n, m, k) = map(int, input().split())
	if k <= 0:
		print(-1)
		return
	adj = [[] for i in range(n)]
	for i in range(m):
		(a, b, w) = map(int, input().split())
		adj[a - 1].append((b - 1, w))
		adj[b - 1].append((a - 1, w))
	storage = list(map(int, input().split()))
	for i in range(k):
		storage[i] -= 1
	storage = set(storage)

	def solve():
		res = math.inf
		for s in storage:
			for (node, w) in adj[s]:
				if node not in storage:
					res = min(res, w)
		return res
	res = solve()
	if res == math.inf:
		print(-1)
	else:
		print(res)
main()


(n, m, k) = [int(x) for x in input().split()]
theinfo = [[0 for c in range(3)] for r in range(m)]
for i in range(m):
	theinfo[i] = [int(x) for x in input().split()]
if k != 0:
	flour = set()
	thenums = [int(x) for x in input().split()]
	for x in thenums:
		flour.add(x)
if k == 0:
	print(-1)
else:
	answer = float('inf')
	for i in range(m):
		u = theinfo[i][0]
		v = theinfo[i][1]
		if u in flour and (not v in flour) or (v in flour and (not u in flour)):
			if theinfo[i][2] < answer:
				answer = theinfo[i][2]
	if answer == float('inf'):
		print(-1)
	else:
		print(answer)


from sys import stdin
(nbVilles, nbRoutes, nbMagasins) = map(int, stdin.readline().split())
voisins = [[] for i in range(nbVilles + 1)]
enAttente = []
estMagasin = [False] * (nbVilles + 1)
for route in range(nbRoutes):
	(depart, arrive, prix) = map(int, stdin.readline().split())
	voisins[depart].append([arrive, prix])
	voisins[arrive].append([depart, prix])
prixMin = 1000 * 1000 * 1000 + 1
villeMin = -1
magasins = []
if nbMagasins != 0:
	magasins = list(map(int, stdin.readline().split()))
	for magasin in magasins:
		estMagasin[magasin] = True
for magasin in magasins:
	for (voisin, prix) in voisins[magasin]:
		if not estMagasin[voisin] and prix < prixMin:
			prixMin = prix
			villeMin = voisin
if villeMin == -1:
	print(-1)
else:
	print(prixMin)


(n, m, k) = map(int, input().split())
a = []
for i in range(m):
	a.append(tuple(map(int, input().split())))
if k == 0:
	print(-1)
else:
	p = set(map(int, input().split()))
	l = 10 ** 10
	for i in range(m):
		if a[i][0] in p and (not a[i][1] in p):
			l = min(l, a[i][2])
		elif a[i][1] in p and (not a[i][0] in p):
			l = min(l, a[i][2])
	if l == 10 ** 10:
		print(-1)
	else:
		print(l)


(n, m, k) = map(int, input().split())
arr = [input().split() for j in range(m)]
(s, v) = (set(), int(1000000000.0 + 3))
if k > 0:
	s = set(input().split())
for i in arr:
	if (i[0] in s) ^ (i[1] in s):
		v = min(v, int(i[2]))
print(-1 if v > int(1000000000.0) else v)


(n, m, k) = map(int, input().split())
t = 0
if k:
	q = {}
	p = []
	for i in range(m):
		p.append(list(map(int, input().split())))
	w = set(map(int, input().split()))
	for i in p:
		if not (i[0] in w and i[1] in w):
			q[i[0]] = min(i[2], q.get(i[0], 10 ** 9))
			q[i[1]] = min(i[2], q.get(i[1], 10 ** 9))
	r = 10 ** 9 + 1
	l = int(r)
	for i in w:
		if i in q:
			r = min(r, q[i])
	if r != l:
		t = 1
print(r if t else -1)


from collections import defaultdict

class Graph:

	def __init__(self, N):
		self.graph = defaultdict(list)

	def show(self):
		print(self.graph)

	def addEdge(self, fr, to, weigh):
		self.graph[fr].append((to, weigh))
		self.graph[to].append((fr, weigh))

	def solve(self, Storage, visited, N):
		Min = 10 ** 9 + 7
		for i in Storage:
			for j in self.graph[i]:
				if visited[j[0] - 1] == False:
					Min = min(Min, j[1])
		return Min
(N, M, K) = map(int, input().split())
G = Graph(N)
visited = [False] * N
for _ in range(M):
	(f, t, we) = map(int, input().split())
	G.addEdge(f, t, we)
if K > 0:
	Storage = [int(x) for x in input().split()]
else:
	Storage = []
for i in Storage:
	visited[i - 1] = True
Ans = G.solve(Storage, visited, N)
if Ans == 10 ** 9 + 7:
	print(-1)
else:
	print(Ans)


import sys
(n, m, k) = map(int, input().split())
if not k % n:
	print(-1)
	sys.exit()
T = tuple((map(int, input().split()) for _ in range(m)))
A = n * [False]
for i in map(int, input().split()):
	A[i - 1] = True
mn = INF = 1 << 30
for (u, v, l) in T:
	if A[u - 1] ^ A[v - 1]:
		mn = min(mn, l)
print(mn if INF > mn else -1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def graph_undirected():
	(n, e, k) = [int(x) for x in input().split()]
	graph = {}
	for i in range(e):
		(vertex, neighbour, weight) = [int(x) for x in input().split()]
		if vertex in graph:
			graph[vertex].append([neighbour, weight])
		else:
			graph[vertex] = [[neighbour, weight]]
		if neighbour in graph:
			graph[neighbour].append([vertex, weight])
		else:
			graph[neighbour] = [[vertex, weight]]
	return (graph, n, k)
(graph, n, k) = graph_undirected()
if k:
	kset = set()
	karr = [int(x) for x in input().split()]
	for i in range(k):
		kset.add(karr[i])
	ans = float('inf')
	for city in karr:
		if city in graph:
			for neighbour in graph[city]:
				if neighbour[0] not in kset:
					ans = min(ans, neighbour[1])
	if ans == float('inf'):
		print(-1)
	else:
		print(ans)
else:
	print(-1)


number = [int(c) for c in input().split(' ')]
it = 1
vershini = [-1]
skladi = []
minimum = []
while it <= number[0]:
	vershini.append([])
	it += 1
it = 1
while it <= number[1]:
	(a, b, c) = [int(c) for c in input().split(' ')]
	vershini[a].append((b, c))
	vershini[b].append((a, c))
	it += 1
it = 1
while it < len(vershini):
	vershini[it].sort(key=lambda vsh: vsh[1])
	it += 1
if number[2] != 0:
	skladi = [int(c) for c in input().split(' ')]
if len(skladi) < number[0] - len(skladi):
	for ab in skladi:
		it = 0
		while it < len(vershini[ab]):
			if not vershini[ab][it][0] in skladi:
				minimum.append(vershini[ab][it][1])
				break
			it += 1
else:
	it = 1
	vse = set(range(1, number[0] + 1))
	goroda = list(vse - set(skladi))
	for ab in goroda:
		it = 0
		while it < len(vershini[ab]):
			if not vershini[ab][it][0] in goroda:
				minimum.append(vershini[ab][it][1])
				break
			it += 1
if skladi != 0 and len(minimum) != 0:
	minimum.sort()
	print(minimum[0])
else:
	print(-1)


def lineInts():
	return [int(i) for i in input().split()]
(n, m, k) = lineInts()
edges = []
for i in range(m):
	edges.append(lineInts())
flours = set()
if k != 0:
	flours = set(lineInts())
pruned = []
for edge in edges:
	if (edge[0] in flours) != (edge[1] in flours):
		pruned.append(edge)
edges = pruned
if len(edges) == 0:
	print(-1)
else:
	edges = sorted(edges, key=lambda x: x[2])
	print(edges[0][2])


import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
factory = defaultdict(lambda : False)
(n, m, k) = map(int, input().split())
graph = defaultdict(lambda : [])
edgeval = defaultdict(lambda : math.inf)
for _ in range(m):
	(u, v, l) = map(int, input().split())
	if u > v:
		(u, v) = (v, u)
	graph[u].append(v)
	graph[v].append(u)
	edgeval[str(u) + ' ' + str(v)] = min(edgeval[str(u) + ' ' + str(v)], l)
if k > 0:
	a = list(map(int, input().split()))
	for i in a:
		factory[i] = True
	ans = math.inf
	for i in a:
		for j in graph[i]:
			if not factory[j]:
				if i <= j:
					ans = min(ans, edgeval[str(i) + ' ' + str(j)])
				else:
					ans = min(ans, edgeval[str(j) + ' ' + str(i)])
	if ans is math.inf:
		print(-1)
	else:
		print(ans)
else:
	print('-1')


import sys
from heapq import heappop, heappush
input = sys.stdin.readline
(n, m, k) = map(int, input().split())
g = {}
for i in range(m):
	(a, b, w) = map(int, input().split())
	if w not in g:
		g[w] = []
	g[w].append((a, b))
keys = list(g.keys())
keys.sort()
if k > 0 and k < n:
	sklad = list(map(int, input().split()))
	minD = -1
	for key in keys:
		for (a, b) in g[key]:
			if a in sklad and b not in sklad or (a not in sklad and b in sklad):
				minD = key
				break
		if minD > 0:
			break
	print(minD)
else:
	print(-1)


(n, m, k) = list(map(int, input().split()))
storages = set()
edges = []
for i in range(m):
	edges.append(list(map(int, input().split())))
if k > 0:
	storages = set(list(map(int, input().split())))
curr_minm = float('inf')
for edge in edges:
	if (edge[0] in storages or edge[1] in storages) and (edge[0] not in storages or edge[1] not in storages) and (edge[2] < curr_minm):
		curr_minm = edge[2]
if curr_minm == float('inf'):
	print(-1)
else:
	print(curr_minm)


def roads_warehouse2city(backery, all_roads):
	return [w for (u, v, w) in all_roads if backery[u] and (not backery[v]) or (backery[v] and (not backery[u]))]

def solve(warehouse, all_roads):
	roads = roads_warehouse2city(warehouse, all_roads)
	return min(roads) if roads else '-1'
(n, m, k) = map(int, input().split())
if k == 0:
	print('-1')
else:
	all_roads = []
	for _ in range(m):
		road = input().split()
		all_roads.append((int(road[0]) - 1, int(road[1]) - 1, int(road[2])))
	warehouse = [False] * n
	for i in input().split():
		warehouse[int(i) - 1] = True
	print(solve(warehouse, all_roads))


import os
import sys
from io import BytesIO, IOBase
from math import inf

def main():
	(n, m, k) = map(int, input().split())
	d = dict()
	for _ in range(m):
		(a, b, c) = map(int, input().split())
		if a not in d:
			d[a] = []
		if b not in d:
			d[b] = []
		d[a].append((b, c))
		d[b].append((a, c))
	if k == 0:
		print(-1)
		exit()
	kk = set(list(map(int, input().split())))
	ans = inf
	for item in kk:
		if item in d:
			for values in d[item]:
				if values[0] not in kk:
					ans = min(ans, values[1])
	if ans == inf:
		print(-1)
	else:
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


import math
(n, m, k) = input().split(' ')
n = int(n)
k = int(k)
m = int(m)
e = {}
for _ in range(m):
	(a, b, c) = input().split(' ')
	a = int(a)
	b = int(b)
	c = int(c)
	x = e.get(a, [])
	x.append((b, c))
	e[a] = x
	x = e.get(b, [])
	x.append((a, c))
	e[b] = x
d = math.inf
if k > 0:
	c = set()
	for i in input().split(' '):
		c.add(int(i))
	for i in c:
		if i in e.keys():
			for j in e[i]:
				if j[0] not in c:
					d = min(d, j[1])
	print(d if d != math.inf else -1)
else:
	print(-1)


(n, m, k) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
u = [0] * (n + 1)
b = []
if k > 0:
	b = map(int, input().split())
for x in b:
	u[x] = 1
c = []
for x in a:
	if u[x[0]] + u[x[1]] == 1:
		c.append(x[2])
if len(c) == 0:
	print(-1)
else:
	print(min(c))


(n, m, k) = map(int, input().split())
a = [input().split() for _ in range(m)]
s = set()
ans = 10 ** 9 + 1
if k:
	s.update(input().split())
for x in a:
	if (x[0] in s) ^ (x[1] in s):
		ans = min(ans, int(x[2]))
if ans < 10 ** 9 + 1:
	print(ans)
else:
	print(-1)


(n_cities, n_roads, n_warehouses) = (int(i) for i in input().split())
roads = []
for i in range(int(n_roads)):
	route = input().split()
	roads.append((int(route[0]), int(route[1]), int(route[2])))
if n_warehouses > 0:
	warehouses = input().split()
	warehouses = set((int(i) for i in warehouses))
else:
	print(-1)
	exit(0)
min_distance = float('inf')
found = False
for j in roads:
	if j[0] in warehouses and j[1] not in warehouses or (j[1] in warehouses and j[0] not in warehouses):
		if j[2] < min_distance:
			min_distance = j[2]
			found = True
print(min_distance) if found else print(-1)


import heapq as hq
(nNodes, nEdges, nFlour) = [int(x) for x in input().split()]
cities = [[] for _ in range(nNodes)]
for _ in range(nEdges):
	edge = [int(x) for x in input().split()]
	cities[edge[0] - 1].append([edge[1] - 1, edge[2]])
	cities[edge[1] - 1].append([edge[0] - 1, edge[2]])
if nFlour <= 0:
	print(-1)
else:
	flour = set([int(x) - 1 for x in input().split()])
	queue = []
	for source in flour:
		for edge in cities[source]:
			if edge[0] not in flour:
				hq.heappush(queue, edge[1])
	if len(queue) <= 0:
		print(-1)
	else:
		print(hq.heappop(queue))


import sys
from collections import defaultdict
MOD = 1000000007

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

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

def input():
	return sys.stdin.readline()

def print_array(a):
	print(' '.join(map(str, a)))

def main():
	(n, m, k) = get_ints()
	edges = []
	for _ in range(m):
		(x, y, l) = get_ints()
		edges.append((x, y, l))
	if k == 0:
		print('-1')
	else:
		a = get_array()
		canBuild = [True] * (n + 1)
		for e in a:
			canBuild[e] = False
		m = -1
		for edge in edges:
			(x, y, l) = edge
			if canBuild[x] ^ canBuild[y]:
				if m == -1:
					m = l
				elif l < m:
					m = l
		print(m)
main()


class Edge:

	def __init__(self, a, b, c):
		self.l = a
		self.r = b
		self.v = c
inf = list(map(int, input().split()))
n = inf[0]
m = inf[1]
k = inf[2]
check = [False] * (n + 2)
edges = [None] * m
for i in range(m):
	inf = list(map(int, input().split()))
	edges[i] = Edge(inf[0], inf[1], inf[2])
ans = 77777777888
if k > 0:
	inf = list(map(int, input().split()))
	for i in inf:
		check[i] = True
for e in edges:
	f = 0
	if check[e.l]:
		f += 1
	if check[e.r]:
		f += 1
	if f == 1:
		if e.v < ans:
			ans = e.v
if ans == 77777777888:
	print(-1)
else:
	print(ans)


def bakery():
	inp = list(map(int, input().split(' ')))
	(citiesCount, roadsCount, bakeriesCount) = (inp[0], inp[1], inp[2])
	roads = []
	bkrs = []
	result = 0
	for i in range(0, roadsCount):
		roads.append(list(map(int, input().split(' '))))
	if bakeriesCount != 0:
		bkrs = list(map(int, input().split(' ')))
	else:
		print(-1)
		return
	bakeries = [0 for i in range(0, citiesCount)]
	for i in range(0, len(bkrs)):
		bakeries[bkrs[i] - 1] = bkrs[i]
	for i in range(0, roadsCount):
		if roads[i][0] == bakeries[roads[i][0] - 1] and roads[i][1] != bakeries[roads[i][1] - 1] or (roads[i][0] != bakeries[roads[i][0] - 1] and roads[i][1] == bakeries[roads[i][1] - 1]):
			if result > roads[i][2] or result == 0:
				result = roads[i][2]
	if result != 0:
		print(result)
	else:
		print(-1)
	return
bakery()


graph = {}
lengths = {}

def apix(x, y):
	if x in graph:
		graph[x].append(y)
	else:
		graph[x] = [y]

def add_edge(a, b, l):
	if (a, b) not in lengths:
		apix(a, b)
		apix(b, a)
		lengths[a, b] = l
		lengths[b, a] = l
	else:
		lengths[a, b] = min(lengths[a, b], l)
		lengths[b, a] = min(lengths[a, b], l)
(n, m, k) = [int(x) for x in input().split()]
for _ in range(m):
	(x, y, l) = [int(x) for x in input().split()]
	add_edge(x, y, l)
ks = []
if k > 0:
	ks = {int(x) for x in input().split()}
if k == 0:
	print('-1')
elif n == k:
	print('-1')
else:
	mm = float('inf')
	for xe in ks:
		if xe in graph:
			for ye in graph[xe]:
				if ye not in ks:
					mm = min(mm, lengths[xe, ye])
	if mm == float('inf'):
		print('-1')
	else:
		print(mm)


from collections import defaultdict
import sys

class graph:

	def __init__(self):
		self.graph = defaultdict(list)

	def min(self, u):
		min = sys.maxsize
		for i in self.graph[u]:
			if i[1] < min:
				min = i[1]
		return min

	def addedge(self, u, v, w):
		newnode = [v, w]
		self.graph[u].append(newnode)
		newnode = [u, w]
		self.graph[v].append(newnode)
[n, m, k] = [int(x) for x in input().split()]
g = graph()
[x, y, z] = [0, 0, 0]
for i in range(m):
	[u, v, w] = [int(x) for x in input().split()]
	if [x, y, z] != [u, v, w]:
		g.addedge(u, v, w)
	[x, y, z] = [u, v, w]
if k == 0:
	print('-1')
else:
	a = [int(x) for x in input().split()]
	b = [0] * n
	for i in a:
		b[i - 1] = 1
	dist = sys.maxsize
	for i in a:
		for j in g.graph[i]:
			if j[1] < dist and b[j[0] - 1] != 1:
				dist = j[1]
	if dist == sys.maxsize:
		print('-1')
	else:
		print(dist)


import sys
sys.setrecursionlimit(10 ** 6)
debug_mode = True if len(sys.argv) > 1 and sys.argv[1] == '-d' else False
if debug_mode:
	import os
	inf = open(os.path.abspath(__file__).replace('.py', '.in'))

	def input():
		return inf.readline()

def main():
	(n, m, k) = list(map(int, input().strip().split()))
	if k > 0:
		roads = [list(map(int, input().strip().split())) for _ in range(m)]
		storages = set(map(int, input().strip().split()))
		probable_road_lengths = list((l for (u, v, l) in roads if (u in storages) != (v in storages)))
		if probable_road_lengths:
			print(min(probable_road_lengths))
		else:
			print(-1)
	else:
		print(-1)
main()
if debug_mode:
	inf.close()


import queue, math
from itertools import repeat

def binarySearch(arr, l, r, x):
	if r >= l:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binarySearch(arr, l, mid - 1, x)
		else:
			return binarySearch(arr, mid + 1, r, x)
	else:
		return -1

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1

def main():
	(n, m, k) = input().split()
	if n == k or k == '0':
		return -1
	G = [[] for i in repeat(None, int(n) + 1)]
	for i in range(int(m)):
		line = list(map(int, input().split()))
		G[line[0]].append((line[1], line[2]))
		G[line[1]].append((line[0], line[2]))
	K = list(map(int, input().split()))
	mergeSort(K)
	ans = math.inf
	for i in K:
		for lst in G[i]:
			if ans > lst[1] and binarySearch(K, 0, len(K) - 1, lst[0]) == -1:
				ans = lst[1]
	return ans if ans != math.inf else -1
print(main())


(n, m, k) = list(map(int, input().split()))
roads = [list(map(int, input().split())) for _ in range(m)]
storages = set(map(int, input().split())) if k > 0 else set()
costs = [w for (c1, c2, w) in roads if (c1 in storages) != (c2 in storages)]
print(min(costs) if costs else -1)


(n, m, k) = map(int, input().split())
graph = [input().split() for j in range(m)]
if k == 0:
	print(-1)
	exit(0)
l = set(input().split())
amt = 10 ** 9 + 1
for g in graph:
	if (g[0] in l) ^ (g[1] in l):
		amt = min(amt, int(g[2]))
print(-1) if amt > 10 ** 9 else print(amt)


from sys import stdin, stdout
(n, m, k) = [int(x) for x in stdin.readline().split()]
d = {}
for i in range(m):
	(u, v, l) = [int(x) for x in stdin.readline().split()]
	if u not in d:
		d[u] = {v: l}
	elif v not in d[u]:
		d[u][v] = l
	elif d[u][v] > l:
		d[u][v] = l
	if v not in d:
		d[v] = {u: l}
	elif u not in d[v]:
		d[v][u] = l
	elif d[v][u] > l:
		d[v][u] = l
if k > 0:
	store = [int(x) for x in stdin.readline().split()]
	store = set(store)
if k == 0:
	stdout.write('-1')
else:
	ans = float('inf')
	for i in store:
		if i in d:
			for j in d[i]:
				if j not in store:
					ans = min(d[i][j], ans)
	if ans == float('inf'):
		stdout.write('-1')
	else:
		stdout.write(str(ans))


f = lambda : map(int, input().split(' '))
(n, m, k) = f()
edges = [list(f()) for _ in range(m)]
storage = set(f()) if k else []
x = [l for (u, v, l) in edges if (u in storage) ^ (v in storage)]
print(min(x) if x else -1)


import sys
from decimal import *

def main():
	(n, m, k) = map(int, sys.stdin.readline().split())
	e = [[] for i in range(n)]
	sk = [False for i in range(n)]
	for i in range(m):
		(u, v, l) = map(int, sys.stdin.readline().split())
		u = u - 1
		v = v - 1
		e[u].append((v, l))
		e[v].append((u, l))
	if k > 0:
		x = list(map(int, sys.stdin.readline().split()))
		for i in x:
			sk[i - 1] = True
	best = None
	for i in range(n):
		if sk[i]:
			continue
		for j in range(len(e[i])):
			(a, l) = e[i][j]
			if sk[a]:
				if best is None:
					best = l
				elif best > l:
					best = l
	if best is None:
		print(-1)
	else:
		print(best)
main()


import heapq
(n, m, k) = map(int, input().split())
edges = []
for i in range(m):
	(u, v, l) = map(int, input().split())
	edges.append((l, u, v))
storage = []
if k:
	storage = set(map(int, input().split()))
heapq.heapify(edges)
while edges:
	edge = heapq.heappop(edges)
	if edge[2] in storage and edge[1] not in storage:
		print(edge[0])
		break
	elif edge[1] in storage and edge[2] not in storage:
		print(edge[0])
		break
else:
	print(-1)


import sys
f = sys.stdin
(n, m, k) = list(map(int, f.readline().strip().split()))
d = dict()
for i in range(m):
	(u, v, l) = list(map(int, f.readline().strip().split()))
	if d.get(u, -1) == -1:
		d[u] = [[v, l]]
	else:
		d[u].append([v, l])
	if d.get(v, -1) == -1:
		d[v] = [[u, l]]
	else:
		d[v].append([u, l])
if k == 0:
	print(-1)
else:
	a = {int(t): 1 for t in f.readline().strip().split()}
	s = 2 * 10 ** 9
	city = -1
	for it in a:
		if d.get(it, -1) == -1:
			continue
		l_city = d[it]
		for c in l_city:
			if s > c[1] and a.get(c[0], -1) == -1:
				s = c[1]
				city = c[0]
	if city == -1:
		print(-1)
	else:
		print(s)


arr = []
kk = []
seen = []
MAX = int(100000000000.0)
mn = MAX
(n, m, k) = map(int, input().split())
seen = [0] * (n + 1)
if k == 0:
	print(-1)
	exit()
for i in range(m):
	arr.append(list(map(int, input().split())))
kk = list(map(int, input().split()))
for i in range(k):
	seen[kk[i]] = 1
for (s, e, v) in arr:
	if seen[s] != seen[e]:
		mn = min(mn, v)
print(mn if mn != MAX else -1)


f = lambda : map(int, input().split(' '))
(n, m, k) = f()
l = [list(f()) for i in range(m)]
u = set(f()) if k else []
x = [c for (a, b, c) in l if (a in u) ^ (b in u)]
print(min(x) if x else -1)


def dijkstra(graph, start, finish, n, inf):
	dist = [inf] * n
	dist[start] = 0
	used = [False] * n
	while True:
		min_dist = inf
		for i in range(n):
			if not used[i] and dist[i] < min_dist:
				min_dist = dist[i]
				min_vertex = i
		if min_dist == inf:
			break
		used[min_vertex] = True
		for j in graph[min_vertex]:
			if dist[j] > dist[min_vertex] + graph[min_vertex][j]:
				dist[j] = dist[min_vertex] + graph[min_vertex][j]
	return dist[finish]
(n, m, k) = map(int, input().split())
graph = [dict() for i in range(n + 1)]
depot = []
inf = 10 ** 9 + 5
minn = inf
for i in range(m):
	(u, v, l) = map(int, input().split())
	if graph[u].get(v, 0) == 0:
		graph[u][v] = l
		graph[v][u] = l
	elif l < graph[u][v]:
		graph[u][v] = l
		graph[v][u] = l
if k > 0:
	depot = set(map(int, input().split()))
	for elem in depot:
		for x in graph[elem]:
			if x not in depot and graph[x][elem] < minn:
				minn = graph[x][elem]
print(minn if minn != inf else -1)


(n, m, k) = map(int, input().split())
r = [input().split() for j in range(m)]
(a, v) = (set(), 10 ** 9 + 1)
if k:
	a.update(input().split())
for ri in r:
	if (ri[0] in a) ^ (ri[1] in a):
		v = min(v, int(ri[2]))
print(-1 if v > 10 ** 9 else v)


(n, m, k) = [int(i) for i in input().split()]
roads = []
storages = [False] * n
for i in range(m):
	roads.append([int(x) for x in input().split()])
sto = []
if k > 0:
	sto = [int(i) for i in input().split()]
for i in sto:
	storages[i - 1] = True
minimum = None
for (a, b, c) in roads:
	if storages[a - 1] and (not storages[b - 1]) or (not storages[a - 1] and storages[b - 1]):
		if minimum is None or c < minimum:
			minimum = c
if minimum is None:
	print(-1)
else:
	print(minimum)


def get_list():
	return list(map(int, input().split()))
(n, m, k) = map(int, input().split())
edge = []
for i in range(m):
	edge.append(get_list())
if k != 0:
	moyda = [0] * (n + 2)
	for i in map(int, input().split()):
		moyda[i] = 1
	ans = 10 ** 18
	for e in edge:
		if moyda[e[0]] != moyda[e[1]]:
			ans = min(ans, e[2])
	if ans == 10 ** 18:
		print(-1)
	else:
		print(ans)
else:
	print(-1)


def main():
	(n, m, k) = map(int, input().split())
	if k == 0 or k == n:
		return -1
	v = []
	for i in range(m):
		s = list(map(int, input().split()))
		v.append(list(reversed(s)))
	v.sort()
	can = [False] * (n + 1)
	for i in map(int, input().split()):
		can[i] = True
	for (p, i, j) in v:
		if can[i] ^ can[j] == True:
			return p
	return -1
print(main())


(n, m, k) = [int(x) for x in input().split()]
x = [0] * m
y = [0] * m
d = [0] * m
for i in range(m):
	(x1, y1, d1) = [int(x) for x in input().split()]
	x[i] = x1
	y[i] = y1
	d[i] = d1
s = [False] * 100001
s1 = []
if k > 0:
	s1 = [int(x) for x in input().split()]
for i in s1:
	s[i] = True
d2 = []
for i in range(m):
	if s[x[i]] and (not s[y[i]]) or (not s[x[i]] and s[y[i]]):
		d2.append(d[i])
if len(d2) == 0:
	print(-1)
else:
	print(min(d2))


(n, m, k) = map(int, input().split(' '))
roads = [list(map(int, input().split(' '))) for i in range(m)]
if k == 0:
	print(-1)
	exit()
a = set(map(int, input().split(' ')))
(flag, mincost) = (False, 0)
for road in roads:
	if (road[0] in a) ^ (road[1] in a):
		if flag:
			mincost = min(mincost, road[2])
		else:
			flag = True
			mincost = road[2]
print(mincost if flag else -1)


(n, m, k) = list(map(int, input().split()))
paths = [input().split() for j in range(m)]
if k == 0:
	print(-1)
	exit(0)
storage = set(input().split())
amount = 10 ** 9 + 1
for v in paths:
	if (v[0] in storage) ^ (v[1] in storage):
		amount = min(amount, int(v[2]))
if amount > 10 ** 9:
	print(-1)
else:
	print(amount)


mat = []
pek = set()
(n, m, k) = list(map(int, input().split()))
arr = []
for i in range(m):
	(u, v, l) = list(map(int, input().split()))
	arr.append([l, u, v])
if k:
	pek = set(map(int, input().split()))
	arr.sort()
	for i in range(m):
		if arr[i][1] in pek and arr[i][2] not in pek:
			print(arr[i][0])
			return
		if arr[i][2] in pek and arr[i][1] not in pek:
			print(arr[i][0])
			return
	print(-1)
else:
	print(-1)


(n, m, a) = map(int, input().split())
M = [list(map(int, input().split())) for i in range(m)]
if a > 0:
	l = list(map(int, input().split()))
ma = 1000000000001
if a > 0:
	l = set(l)
	for i in range(m):
		if M[i][0] in l and M[i][1] not in l or (M[i][1] in l and M[i][0] not in l):
			ma = min(ma, M[i][2])
	if ma == 1000000000001:
		print(-1)
	else:
		print(ma)
else:
	print(-1)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [tuple(map(int, l.split())) for l in sys.stdin]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, m, k) = LI()
	aa = [LI() for _ in range(m)]
	s = set(LI())
	r = inf
	for (a, b, c) in aa:
		if (a in s) != (b in s):
			if r > c:
				r = c
	if r == inf:
		return -1
	return r
print(main())


from collections import Counter
(a, b, c) = map(int, input().split())
if c == 0:
	exit(print(-1))
z = []
ans = 10 ** 13
for _ in ' ' * b:
	z.append(list(map(int, input().split())))
d = Counter(list(map(int, input().split())))
for i in range(b):
	if d[z[i][0]] != d[z[i][1]]:
		ans = min(ans, z[i][2])
if ans == 10 ** 13:
	print(-1)
else:
	print(ans)


(n, m, k) = map(int, input().split())
li = []
for i in range(m):
	li += [list(map(int, input().split()))]
if k != 0:
	k = set(map(int, input().split()))
if k == 0 or k == n:
	print('-1')
	exit()
else:
	storage = set(range(1, n + 1)) - set(k)
	mi = 10 ** 9 + 5
	for (u, v, l) in li:
		if u in k and v in storage or (v in k and u in storage):
			if l < mi:
				mi = l
	if mi != 10 ** 9 + 5:
		print(mi)
	else:
		print('-1')


from sys import stdin, stdout
(n, m, k) = map(int, stdin.readline().split())
vertices = [[] for i in range(n + 1)]
for i in range(m):
	(a, b, w) = map(int, stdin.readline().split())
	vertices[a].append((b, w))
	vertices[b].append((a, w))
if k:
	storages = set(map(int, stdin.readline().split()))
	ans = float('inf')
	for num in storages:
		for v in vertices[num]:
			if v[0] not in storages:
				ans = min(ans, v[1])
	if ans == float('inf'):
		stdout.write('-1')
	else:
		stdout.write(str(ans))
else:
	stdout.write('-1')


inputData = list(map(int, input().split()))
roads = []
stock = [False] * (inputData[0] + 1)
for i in range(inputData[1]):
	roads.append(list(map(int, input().split())))
if inputData[2] > 0:
	for i in list(map(int, input().split())):
		stock[i] = True
m = -1
for i in roads:
	if (m == -1 or i[2] < m) and stock[i[0]] != stock[i[1]]:
		m = i[2]
print(m)


(n, m, k) = map(int, input().split())
d = []
for i in range(m):
	(u, v, l) = map(int, input().split())
	d.append((u, v, l))
if k == 0:
	print(-1)
else:
	s = set(map(int, input().split()))
	ans = uv = 1111111111111111111111
	for (u, v, l) in d:
		if u not in s and v in s or (v not in s and u in s):
			ans = min(ans, l)
	if ans == uv:
		print(-1)
	else:
		print(ans)


def solve():
	(n, m, k) = list(map(int, input().split()))
	graph = [dict() for i in range(n + 1)]
	for i in range(m):
		(u, v, l) = list(map(int, input().split()))
		if v not in graph[u]:
			graph[u][v] = l
			graph[v][u] = l
		else:
			graph[u][v] = min(graph[u][v], l)
			graph[v][u] = min(graph[v][u], l)
	if k > 0:
		a = list(map(int, input().split()))
		warehouse = [False] * (10 ** 5 + 1)
		for i in a:
			warehouse[i] = True
		ans = 2000000001
		for i in range(k):
			for key in graph[a[i]]:
				if not warehouse[key]:
					ans = min(ans, graph[a[i]][key])
		if ans == 2000000001:
			print(-1)
		else:
			print(ans)
		return
	print(-1)
solve()


inp = input().strip().split()
(n, m, k) = (int(inp[0]), int(inp[1]), int(inp[2]))
c1 = [-1 for i in range(m + 1)]
c2 = [-1 for i in range(m + 1)]
l = [-1 for i in range(m + 1)]
store = [False for i in range(n + 1)]
for i in range(m):
	inp = input().strip().split()
	(c1[i], c2[i], l[i]) = (int(inp[0]), int(inp[1]), int(inp[2]))
if k <= 0:
	print('-1')
else:
	inp = input().strip().split()
	ans = 1000000000 + 10
	for i in inp:
		store[int(i)] = True
	for i in range(m):
		(x, y, d) = (c1[i], c2[i], l[i])
		if store[x] and (not store[y]):
			ans = min(ans, d)
		if store[y] and (not store[x]):
			ans = min(ans, d)
	if ans == 1000000000 + 10:
		print('-1')
	else:
		print(ans)


(n, m, k) = map(int, input().split())
grid = [dict() for i in range(n + 1)]
for i in range(m):
	(u, v, w) = map(int, input().split())
	if u not in grid[v]:
		grid[u][v] = w
		grid[v][u] = w
	else:
		grid[u][v] = min(grid[u][v], w)
		grid[v][u] = min(grid[v][u], w)
if k > 0:
	w = set(map(int, input().split()))
	flag = False
	mind = 10000000000.0
	for x in w:
		for (v, l) in grid[x].items():
			if v not in w:
				mind = min(mind, l)
				flag = True
	if flag:
		print(mind)
	else:
		print(-1)
else:
	print(-1)


(n, m, k) = map(int, input().split())
a = list()
for i in range(m):
	(u, v, l) = map(int, input().split())
	a.append((u, v, l))
if k > 0:
	b = set(map(int, input().split()))
	minimum = -1
	for j in a:
		if j[0] in b and (not j[1] in b) or (j[1] in b and (not j[0] in b)):
			if minimum == -1:
				minimum = j[2]
			else:
				minimum = j[2] if minimum > j[2] else minimum
	print(minimum)
else:
	print(-1)


import math, fractions, collections
(n, m, k) = [int(x) for x in input().split()]
storage = [0] * (n + 1)
cities = [list(map(int, input().split())) for x in range(m)]
if k == 0 or k == n:
	print(-1)
else:
	for x in map(int, input().split()):
		storage[x] = 1
	ans = 1000000000.0 + 5
	for c in cities:
		if storage[c[0]]:
			if not storage[c[1]]:
				ans = min(ans, c[2])
		if storage[c[1]]:
			if not storage[c[0]]:
				ans = min(ans, c[2])
	print(ans if ans != 1000000000.0 + 5 else -1)


import sys, itertools, math, collections, random

def ia():
	return [int(i) for i in sys.stdin.readline().strip().split(' ')]

def ii():
	return int(sys.stdin.readline().strip())

def istr():
	return sys.stdin.readline().strip()
(n, m, k) = ia()
E = {}
N = collections.defaultdict(list)
for _ in range(m):
	(a, b, l) = ia()
	if (a, b) in E:
		E[a, b] = min(l, E[a, b])
	else:
		E[a, b] = l
	if (b, a) in E:
		E[b, a] = min(l, E[b, a])
	else:
		E[b, a] = l
	N[a].append(b)
	N[b].append(a)
if k > 0:
	S = set(ia())
else:
	S = set()
ans = 10 ** 10
for s in S:
	for n in N[s]:
		if not n in S:
			ans = min(ans, E[n, s])
if ans < 10 ** 10:
	print(ans)
else:
	print(-1)


def main():
	(n, m, k) = map(int, input().split())
	graph = [[] for x in range(n + 1)]
	seen = [0] * (n + 1)
	min_nb = 1000 * 1000 * 1000 * 1000
	for i in range(m):
		(a, b, c) = map(int, input().split())
		graph[a].append((b, c))
		graph[b].append((a, c))
	if k > 0:
		fl = list(map(int, input().split()))
		for fli in fl:
			seen[fli] = 1
	for i in range(1, n + 1):
		for nei in graph[i]:
			if seen[i] != seen[nei[0]]:
				min_nb = min(min_nb, nei[1])
	if min_nb == 1000 * 1000 * 1000 * 1000:
		print(-1)
	else:
		print(min_nb)
main()


def solve():
	ans = float('inf')
	(n, m, k) = map(int, input().split())
	arr = [list(map(int, input().split())) for i in range(m)]
	if k == 0:
		return -1
	goal = set(map(int, input().split()))
	for i in arr:
		[u, v, l] = i
		if (u in goal) ^ (v in goal):
			ans = min(ans, l)
	return ans if ans != float('inf') else -1
print(solve())


from math import inf
import sys
(n, m, k) = map(int, sys.stdin.readline().strip().split())
edges = []
if k == 0:
	print(-1)
	quit()
for i in range(m):
	(u, v, l) = map(int, sys.stdin.readline().strip().split())
	edges.append((u, v, l))
warehouses = list(map(int, sys.stdin.readline().strip().split()))
canBuild = [True] * (n + 1)
for warehouse in warehouses:
	canBuild[warehouse] = False
ans = inf
for edge in edges:
	(u, v, l) = edge
	if canBuild[u] ^ canBuild[v]:
		ans = min(ans, l)
print(-1 if ans == inf else ans)


from collections import defaultdict
from itertools import chain

def solve(graph):
	if graph:
		min_way = min(chain(*graph.values()))
		return min_way + 1
	return '-1'

def construct_graph(backery, edges):
	graph = defaultdict(list)
	for (u, v, w) in edges:
		if backery[u] and (not backery[v]):
			graph[u].append(w)
		elif backery[v] and (not backery[u]):
			graph[v].append(w)
	return graph
(n, m, k) = map(int, input().split())
if k == 0:
	print('-1')
else:
	edges = [map(lambda x: int(x) - 1, input().split()) for _ in range(m)]
	backery = [False] * n
	for i in map(lambda x: int(x) - 1, input().split()):
		backery[i] = True
	graph = construct_graph(backery, edges)
	print(solve(graph))


(n, m, k) = input().split()
n = int(n)
m = int(m)
k = int(k)
graphs = {i + 1: {} for i in range(n)}
for _ in range(m):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	if graphs[a].get(b) != None:
		graphs[a][b] = min(graphs[a][b], c)
	else:
		graphs[a][b] = c
	if graphs[b].get(a) != None:
		graphs[b][a] = min(graphs[b][a], c)
	else:
		graphs[b][a] = c
storages = {}
if k > 0:
	storages = input().split()
	storages = {int(s) for s in storages}
ans = -1
for (v, edges) in graphs.items():
	if v in storages:
		for (neighbour, dist) in edges.items():
			if neighbour not in storages:
				if ans == -1:
					ans = dist
				else:
					ans = min(ans, dist)
print(ans)


from sys import *
(n, m, k) = (int(z) for z in input().split())
G = dict()
for i in range(n):
	G[i + 1] = set()
e = dict()
for i in range(m):
	(u, v, l) = (int(z) for z in input().split())
	G[u].add(v)
	G[v].add(u)
	if e.get((u, v)):
		e[u, v] = min(l, e[u, v])
		e[v, u] = min(l, e[u, v])
	else:
		e[u, v] = l
		e[v, u] = l
ch = set()
if k != 0:
	c = [int(z) for z in input().split()]
	for i in c:
		ch.add(i)
else:
	print(-1)
	exit(0)
uu = 10 ** 10
for i in ch:
	for j in G[i]:
		if j not in ch:
			uu = min(e[i, j], uu)
if uu < 10 ** 10:
	print(uu)
else:
	print(-1)


(n, m, k) = map(int, input().split())
inf = 10 ** 15
near = inf
g = []
for i in range(m):
	g.append(list(map(int, input().split())))
where = []
if k != 0:
	where = set(map(int, input().split()))
if where != set():
	for i in range(m):
		if g[i][2] < near and (g[i][0] in where) ^ (g[i][1] in where):
			near = g[i][2]
if near == inf:
	print(-1)
else:
	print(near)


(n, m, k) = map(int, input().split())
f = []
for i in range(m):
	f.append(list(map(int, input().split())))
if k == 0:
	print('-1')
	exit()
shops = [0] * (n + 1)
ans = []
s = list(map(int, input().split()))
for i in s:
	shops[i] = 1
for i in f:
	if shops[i[0]] + shops[i[1]] == 1:
		ans.append(i[2])
if len(ans) > 0:
	print(min(ans))
else:
	print('-1')


(cities, roads, storages) = list(map(int, input().split(' ')))
graph = {}
for i in range(cities):
	graph[i + 1] = {}
	graph[i + 1].update({'storage': False})
for i in range(roads):
	(source, destination, length) = list(map(int, input().split(' ')))
	if destination in graph[source].keys():
		prevLength = graph[source].get(destination)
		graph[source].update({destination: min(prevLength, length)})
	else:
		graph[source].update({destination: length})
	if source in graph[destination].keys():
		prevLength = graph[destination].get(source)
		graph[destination].update({source: min(prevLength, length)})
	else:
		graph[destination].update({source: length})
allStorages = []
if storages > 0:
	allStorages = list(map(int, input().split(' ')))
for i in allStorages:
	graph[i].update({'storage': True})
minimumDistance = 10 ** 10
for i in allStorages:
	for j in graph[i].keys():
		if j != 'storage' and (not graph[j].get('storage')):
			minimumDistance = min(minimumDistance, graph[i].get(j))
if minimumDistance == 10 ** 10:
	print(-1)
else:
	print(minimumDistance)


import sys
import io
import os
total = 0
failed = 0

def debug(*args):
	if 'LOCALTEST' in os.environ:
		print(*args, file=sys.stderr)

def run(test, res):
	x = io.StringIO()
	with io.StringIO(test) as sys.stdin:
		with x as sys.stdout:
			work()
			z = x.getvalue().strip()
	sys.stdout = sys.__stdout__
	print('Passed?', z == res)
	print('Expected: ', res)
	print('Actual  : ', z)
	global total, failed
	total += 1
	failed += 1 if z != res else 0

def work():
	(n, m, k) = map(int, input().split())
	if k == 0:
		print(-1)
		return
	roads = []
	for i in range(m):
		roads.append(map(int, input().split()))
	a = set(map(int, input().split()))
	ok = [x in a for x in range(n + 1)]
	min = -1
	for r in roads:
		(u, m, l) = r
		if ok[u] != ok[m] and (l < min or min == -1):
			min = l
	print(min)

def test():
	run('5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5', '3')
	run('3 7 0\n1 3 9\n1 2 5\n1 2 21\n1 2 12\n1 2 13\n2 3 19\n2 3 8', '-1')
	run('3 1 1\n1 2 3\n3', '-1')
if 'LOCALTEST' in os.environ:
	test()
	print('\n Result: %s (%d total, %d failed)' % ('FAILED' if failed > 0 else 'PASSED', total, failed))
else:
	work()


import sys
(n, m, k) = map(int, sys.stdin.readline().split())
if k == 0:
	print('-1')
else:
	M = [[] for i in range(n + 1)]
	S = [False] * (n + 1)
	for i in range(m):
		(s, e, l) = map(int, sys.stdin.readline().split())
		M[s].append((e, l))
		M[e].append((s, l))
	stocks = list(map(int, sys.stdin.readline().split()))
	for s in stocks:
		S[s] = True
	answ = 10 ** 10
	for s in stocks:
		for (e, l) in M[s]:
			if not S[e] and answ > l:
				answ = l
	if answ < 10 ** 10:
		print(answ)
	else:
		print('-1')


(n, m, k) = map(int, input().split())
l = []
l1 = set()
max1 = 1000000001
for _ in range(m):
	l.append(input().split())
if k:
	l1.update(input().split())
for i in l:
	if (i[0] in l1) ^ (i[1] in l1):
		max1 = min(max1, int(i[2]))
if max1 != 1000000001:
	print(max1)
else:
	print(-1)


(n, m, k) = map(int, input().split())
graph = []
for _ in range(m):
	(u, v, w) = map(int, input().split())
	graph.append((u, v, w))
if k > 0:
	flour = set(map(int, input().split()))
minw = 10 ** 10
if k == 0:
	print(-1)
else:
	for i in range(len(graph)):
		(u, v, w) = graph[i]
		if u in flour:
			if v not in flour:
				minw = min(minw, w)
		if v in flour:
			if u not in flour:
				minw = min(minw, w)
	print(-1) if minw == 10 ** 10 else print(minw)


(n, m, k) = map(int, input().split())
arr = []
for _ in range(m):
	arr.append(list(map(int, input().split())))
if k > 0:
	flours = list(map(int, input().split()))
	mp = {}
	for i in flours:
		mp[i] = 0
if k == 0:
	print(-1)
else:
	ans = []
	for i in range(m):
		if arr[i][0] in mp and arr[i][1] not in mp:
			ans.append(arr[i][2])
		if arr[i][1] in mp and arr[i][0] not in mp:
			ans.append(arr[i][2])
	if len(ans) == 0:
		print(-1)
	else:
		print(min(ans))


(n, m, k) = (int(x) for x in input().split())
g = []
for i in range(m):
	(u, v, l) = (int(x) for x in input().split())
	g.append([u, v, l])
	g.append([v, u, l])
if k > 0:
	a = set([int(x) for x in input().split()])
	min = 2000000000
	for i in range(len(g)):
		if g[i][0] in a and g[i][1] not in a and (g[i][2] < min) and (g[i][2] != 0):
			min = g[i][2]
	print(min if min != 2000000000 else -1)
else:
	print(-1)


(n, m, k) = map(int, input().split())
A = [0] * m
for i in range(m):
	A[i] = list(map(int, input().split()))
if k != 0:
	ans = set(list(map(int, input().split())))
if k == 0 or k == n:
	print(-1)
else:
	per = float('infinity')
	for i in range(m):
		if A[i][0] in ans and A[i][1] not in ans or (A[i][0] not in ans and A[i][1] in ans):
			per = min(per, A[i][2])
	if per != float('infinity'):
		print(per)
	else:
		print(-1)


from collections import deque
Z = -1
(n, m, k) = map(int, input().split())
G = {}
L = {}
for i in range(n):
	G[i + 1] = []
for i in range(m):
	(a, b, c) = map(int, input().split())
	G[a].append(b)
	G[b].append(a)
	l = c
	if (a, b) in L:
		l = min(c, L[a, b])
	L[a, b] = l
	L[b, a] = l
X = []
if k > 0:
	X = set(map(int, input().split()))
for w in L:
	if w[0] in X and w[1] not in X:
		if Z == -1:
			Z = L[w]
		else:
			Z = min(L[w], Z)
print(Z)


import sys
from collections import defaultdict
(n, m, k) = map(int, sys.stdin.readline().split())
d = defaultdict(set)
for _ in range(m):
	(u, v, l) = map(int, sys.stdin.readline().split())
	d[l].add((u, v))
A = set(map(int, sys.stdin.readline().split()))
for i in sorted(d.keys()):
	found = False
	for item in d[i]:
		(u, v) = item
		if u in A and v not in A or (u not in A and v in A):
			print(i)
			found = True
			break
	if found:
		break
else:
	print(-1)


(n, m, k) = map(int, input().split())
e = []
for i in range(m):
	e.append(tuple(map(int, input().split())))
if k > 0:
	a = set(list(map(int, input().split())))
else:
	a = {}
ans = 10 ** 18
for i in e:
	if i[0] in a and i[1] in a:
		continue
	if i[0] in a or i[1] in a:
		ans = min(ans, i[2])
if ans == 10 ** 18:
	print(-1)
	exit()
print(ans)


firstLineOfInput = input().split()
(n, m, k) = (int(firstLineOfInput[0]), int(firstLineOfInput[1]), int(firstLineOfInput[2]))
roads = []
for i in range(m):
	roads.append(input().split())
storageCitys = {}
if k > 0:
	storageCitys = set(input().split())
minPay = -1
for road in roads:
	aCityOfThisRoad = road[0]
	anotherCityOfThisRoad = road[1]
	if aCityOfThisRoad in storageCitys and anotherCityOfThisRoad not in storageCitys or (aCityOfThisRoad not in storageCitys and anotherCityOfThisRoad in storageCitys):
		lengthOfThisRoad = int(road[2])
		if minPay == -1:
			minPay = lengthOfThisRoad
		elif lengthOfThisRoad < minPay:
			minPay = lengthOfThisRoad
print(minPay)


import sys
(n, m, p) = map(int, input().split())
g = {i: [] for i in range(1, n + 1)}
for i in range(m):
	(u, v, l) = map(int, input().split())
	g[u].append((v, l))
	g[v].append((u, l))
if p > 0:
	k = set(map(int, input().split()))
if p == 0:
	print(-1)
else:
	mm = sys.maxsize
	for i in k:
		for j in g[i]:
			if j[0] not in k:
				mm = min(mm, j[1])
	if mm == sys.maxsize:
		print(-1)
	else:
		print(mm)


r = lambda : map(int, input().split())
(n, m, k) = r()
roads = [list(r()) for _ in range(m)]
if k:
	storage = set(r())
	try:
		m = min((d for (a, b, d) in roads if (a in storage) != (b in storage)))
		print(m)
	except:
		print(-1)
else:
	print(-1)


(n, m, k) = map(int, input().split())
e = [None] * m
s = [False] * (n + 1)
for i in range(m):
	e[i] = tuple(map(int, input().split()))
if k > 0:
	for i in input().split():
		s[int(i)] = True
r = int(2000000000.0)
for i in e:
	if s[i[0]] ^ s[i[1]]:
		r = min(r, i[2])
if r == int(2000000000.0):
	print(-1)
else:
	print(r)


(n, m, k) = map(int, input().split())
edge = [None] * m
node = [False] * (n + 1)
for i in range(m):
	edge[i] = list(map(int, input().split()))
if k > 0:
	for i in input().split():
		node[int(i)] = True
ans = int(2000000000.0)
for i in edge:
	if node[i[0]] ^ node[i[1]]:
		ans = min(ans, i[2])
if ans == int(2000000000.0):
	print(-1)
else:
	print(ans)


(n, m, k) = map(int, input().split())
MAXL = 1000000001
dist = [{} for _ in range(n + 1)]
for _ in range(m):
	(u, v, length) = map(int, input().split())
	dist[u][v] = min(length, dist[u].get(v, MAXL))
	dist[v][u] = min(length, dist[v].get(u, MAXL))
flour_keep = set()
if k > 0:
	flour_keep = set(map(int, input().split()))
ans = MAXL
for t in flour_keep:
	for nei in dist[t]:
		if nei not in flour_keep:
			ans = min(ans, dist[t][nei])
print(ans if ans < MAXL else -1)


def binary_search(seq, t):
	min = 0
	max = len(seq) - 1
	while True:
		if max < min:
			return -1
		m = (min + max) // 2
		if seq[m] < t:
			min = m + 1
		elif seq[m] > t:
			max = m - 1
		else:
			return m
(n, m, k) = [int(i) for i in input().split()]
s = [[] for i in range(n)]
for i in range(m):
	(u, v, l) = [int(i) for i in input().split()]
	s[u - 1].append([v - 1, l])
	s[v - 1].append([u - 1, l])
if k == 0 or k == n:
	print(-1)
else:
	o = [int(i) - 1 for i in input().split()]
	o.sort()
	a = 10 ** 9 + 1
	for i in o:
		for j in s[i]:
			if binary_search(o, j[0]) == -1:
				a = min(j[1], a)
	if a == 10 ** 9 + 1:
		print(-1)
	else:
		print(a)


import sys
(n, m, k) = map(int, input().split())
l = []
for i in range(m):
	(x, y, w) = map(int, input().split())
	l.append((x, y, w))
if k == 0:
	print(-1)
else:
	lk = [0] * (n + 1)
	ll = list(map(int, input().split()))
	for i in ll:
		lk[i] = 1
	ans = -1
	flag = 0
	for i in l:
		if lk[i[0]] and (not lk[i[1]]) or (not lk[i[0]] and lk[i[1]]):
			if flag == 0:
				ans = i[2]
				flag = 1
			elif i[2] < ans:
				ans = i[2]
	print(ans)


import sys

def main():
	(n, m, k) = [int(x) for x in input().split()]
	edges = [[] for x in range(n + 1)]
	for i in range(m):
		(x, y, cost) = [int(x) for x in input().split()]
		edges[x].append((y, cost))
		edges[y].append((x, cost))
	if k <= 0:
		print('-1')
		return
	storages = set()
	for i in [int(x) for x in input().split()]:
		storages.add(i)
	minCost = sys.maxsize
	for i in storages:
		for edge in edges[i]:
			if edge[0] not in storages:
				minCost = min(minCost, edge[1])
	if minCost == sys.maxsize:
		print('-1')
	else:
		print(minCost)
main()


(n, m, k) = map(int, input().split())
ans = 10 ** 19
edges = []
for i in range(m):
	(u, v, l) = map(int, input().split())
	edges.append((u, v, l))
if k == 0:
	print(-1)
	exit()
storages = set(map(int, input().split()))
for (u, v, l) in edges:
	if u not in storages and v in storages or (v not in storages and u in storages):
		ans = min(ans, l)
if ans != 10 ** 19:
	print(ans)
else:
	print(-1)


(n, m, k) = map(int, input().split())
vertices = {}
for i in range(0, n):
	vertices[i] = []
for j in range(0, m):
	(s, d, dist) = map(int, input().split())
	vertices[s - 1].append((d - 1, dist))
	vertices[d - 1].append((s - 1, dist))
if k != 0:
	lis = [int(i) - 1 for i in input().split()]
else:
	lis = []
take = [True for i in range(0, n)]
for i in lis:
	take[i] = False
min = -1
for i in lis:
	for x in vertices[i]:
		if take[x[0]] == True:
			if x[1] < min or min == -1:
				min = x[1]
print(min)


import sys, heapq
fin = sys.stdin
fout = sys.stdout
(n, m, k) = map(int, fin.readline().split())
g = [0] * n
for i in range(n):
	g[i] = []
for i in range(m):
	(start, end, cost) = map(int, fin.readline().split())
	g[start - 1].append((end - 1, cost))
	g[end - 1].append((start - 1, cost))
stores = []
if k > 0:
	stores = list(map(int, fin.readline().split()))
for i in range(len(stores)):
	stores[i] -= 1
used = [-1] * n
INF = 10 ** 9 + 3
d = [INF] * n
heap = []
for cur in stores:
	heap.append((0, cur))
	d[cur] = 0
heapq.heapify(heap)

def find(color):
	while len(heap) != 0:
		cur = heapq.heappop(heap)
		if used[cur[1]] == color:
			continue
		u = cur[1]
		used[u] = color
		for x in g[u]:
			if d[x[0]] > d[u] + x[1]:
				d[x[0]] = d[u] + x[1]
				heapq.heappush(heap, (d[x[0]], x[0]))
find(0)
minn = INF
for i in range(len(d)):
	if d[i] != 0 and d[i] != INF and (d[i] < minn):
		minn = d[i]
if minn == INF:
	fout.write('-1')
else:
	fout.write(str(minn))


(n, m, k) = map(int, input().strip().split())
gr = [[] for i in range(n)]
for i in range(m):
	(x, y, w) = map(int, input().strip().split())
	gr[x - 1].append([y, w])
	gr[y - 1].append([x, w])
arr = []
if k != 0:
	arr = list(map(int, input().strip().split()))
d = {}
for i in range(len(arr)):
	d[arr[i]] = 1
min = [0, 10000000000]
for i in range(k):
	if len(arr) == 0:
		break
	for x in gr[arr[i] - 1]:
		if x[0] in d:
			continue
		if x[1] < min[1]:
			min = x
if min[1] == 10000000000:
	print(-1)
else:
	print(min[1])


(n, m, k) = [int(item) for item in input().split()]
if k == 0:
	print(-1)
else:
	links = []
	for i in range(m):
		line = [int(item) for item in input().split()]
		line = [line[2], line[0], line[1]]
		links.append(line)
	storage = set([int(item) for item in input().split()])
	links = sorted(links)
	for link in links:
		if link[1] not in storage and link[2] in storage or (link[1] in storage and link[2] not in storage):
			print(link[0])
			break
	else:
		print(-1)


(n, m, k) = map(int, input().split())
l = []
for i in range(m):
	l.append(list(map(int, input().split())))
if k == 0:
	print('-1')
	exit()
else:
	s = list(map(int, input().split()))
	x = [0] * (n + 1)
	for i in s:
		x[i] = 1
	ans = []
	for i in l:
		if x[i[0]] + x[i[1]] == 1:
			ans.append(i[2])
	if ans == []:
		print('-1')
	else:
		print(min(ans))


from collections import defaultdict
(n, m, k) = [int(x) for x in input().split()]
u = [0]
v = [0]
d = [0]
for i in range(m):
	(t1, t2, t3) = [int(x) for x in input().split()]
	u.append(t1)
	v.append(t2)
	d.append(t3)
flour = defaultdict(lambda : 0, {})
if k > 0:
	f = [int(x) for x in input().split()]
	for shop in f:
		flour[shop] = 1
INT_MAX = 10 ** 9 + 7
ans = INT_MAX
for i in range(1, m + 1):
	if flour[u[i]] ^ flour[v[i]]:
		ans = min(ans, d[i])
if ans == INT_MAX:
	print(-1)
else:
	print(ans)


(n, m, k) = map(int, input().split())
roads = [input().split() for _ in range(m)]
storageCitys = {}
if k > 0:
	storageCitys = set(input().split())
minPay = -1
for road in roads:
	aCityOfThisRoad = road[0]
	anotherCityOfThisRoad = road[1]
	if aCityOfThisRoad in storageCitys and anotherCityOfThisRoad not in storageCitys or (aCityOfThisRoad not in storageCitys and anotherCityOfThisRoad in storageCitys):
		lengthOfThisRoad = int(road[2])
		if minPay == -1:
			minPay = lengthOfThisRoad
		elif lengthOfThisRoad < minPay:
			minPay = lengthOfThisRoad
print(minPay)


from sys import stdin

def main():
	(n, m, k) = map(int, input().split())
	if k in (0, n):
		print(-1)
		return
	(l, t) = (stdin.read().splitlines(), [True] * (n + 1))
	for i in map(int, l.pop().split()):
		t[i] = False
	inf = res = 2 ** 48
	for s in l:
		(a, b, c) = map(int, s.split())
		if t[a] != t[b] and res > c:
			res = c
	print(res if res < inf else -1)
main()


(n, m, k) = input().strip().split(' ')
path = list()
for i in range(int(m)):
	Line = input().strip().split(' ')
	path.append(Line)
storage = set()
if k != '0':
	temp = input().strip().split(' ')
for i in range(int(k)):
	storage.add(temp[i])
ans = 10000000000
change = False
for i in range(int(m)):
	road = path[i]
	(city_A, city_B, distance) = road
	if (city_A in storage) ^ (city_B in storage):
		if ans > int(distance):
			ans = int(distance)
			change = True
if not change:
	print(-1)
else:
	print(ans)