https://www.acmicpc.net/problem/1939
from collections import deque
n, m = map(int, input().split())
adj = [[] for _ in range(n+1)]
def bfs(c):
queue = deque([start_node])
# print("inside bfs", queue)
visited = [False] * (n + 1)
# print("visited", n, visited)
visited[start_node] = True
while queue:
x = queue.popleft()
# print("while queue", x, adj[x])
for y, weight in adj[x]:
if not visited[y] and weight >= c:
visited[y] = True
queue.append(y)
# print(visited[end_node])
return visited[end_node]
start = 1000000000
end = 1
for _ in range(m):
x, y, weight = map(int, input().split())
adj[x].append((y, weight))
adj[y].append((x, weight))
# print(adj)
start = min(start, weight)
end = max(end, weight)
start_node, end_node = map(int, input().split())
result = start
while(start <= end):
mid = (start + end) // 2
if bfs(mid):
result = mid
start = mid + 1
else:
end = mid - 1
print(result)