# 1916번. 최소비용 구하기
importheapqimportsysinput=sys.stdin.readlinen=int(input())m=int(input())s=[[]foriinrange(n+1)]dist=[1e9foriinrange(n+1)]foriinrange(m):start,end,cost=map(int,input().split())s[start].append([end,cost])# 구하고자 하는 출발, 도착 번호
start,end=map(int,input().split())defdijkstra(start):dist[start]=0heap=[]heapq.heappush(heap,[dist[start],start])whileheap:curDis,curNode=heapq.heappop(heap)ifdist[curNode]<curDis:continuefora,wins[curNode]:distance=curDis+wifdistance<dist[a]:dist[a]=distanceheapq.heappush(heap,[distance,a])returndistdijkstra(start)print(dist[end])