import sys import math from collections import deque,Counter from sys import stdin #sys.setrecursionlimit(10**7) int1=lambda x: int(x)-1 inp=lambda :int(input()) mi=lambda :map(int,input().split()) li=lambda :list(mi()) mi1=lambda :map(int1,input().split()) li1=lambda :list(mi1()) mis=lambda :map(str,input().split()) lis=lambda :list(mis()) stinput=lambda :stdin.readline()[:-1] stinp=lambda :int(stinput()) stmi=lambda :map(int, stdin.readline().split()) stli=lambda :list(stmi()) stmi1=lambda :map(int1, stdin.readline().split()) stli1=lambda :list(stmi1()) stmis=lambda :stdin.readline()[:-1] pr=print from collections import defaultdict """ #初期値 0 d=defaultdict(int) #初期値 1 d=defaultdict(lambda:1) """ mod=10**9+7 Mod=998244353 INF=10**18 ans=0 #UnionFind from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): # {0: [0, 2], 1: [1, 3, 4, 5]} # 辞書で返す # d=uf.all_group_members() で使う group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) n=inp() uf=UnionFind(n) for i in range(10**5): a,b,c=mi() a-=1 b-=1 uf.union(a,b) if uf.size(0)==n: print(c) exit()