import heapq n = int(input()) to = [[] for _ in range(n)] for _ in range(n*(n-1)//2): a,b,c = map(int,input().split()) to[a-1].append([c,b-1]) to[b-1].append([c,a-1]) cost = [10 ** 101] * n cost[0] = 0 visited = [False] * n visited[0] = 0 lis = [] heapq.heapify(lis) heapq.heappush(lis,(0,0)) while(lis): cc,a = heapq.heappop(lis) for c2,v in to[a]: if((visited[v]) & (cost[v] < c2)): continue visited[v] = True cost[v] = min(cost[v],c2) heapq.heappush(lis,(cost[v],v)) print(cost[-1])