import java.util.*;
public class Dijkstra {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in); // 標準入力から読む
        int n = sc.nextInt(); // ノードの数
        int m = sc.nextInt(); // エッジの数
        int[][] mat = new int[n][n]; // ノードの接続関係を表す隣接行列
        for (int i=0; i<n; i++) // 隣接行列を初期化する
            for (int j=0; j<n; j++)
                mat[i][j] = (i==j) ? 0 : -1;
        for (int i=0; i<m; i++) { // エッジの定義を読み込む
            int s = sc.nextInt(); // 始点
            int t = sc.nextInt(); // 終点
            int w = sc.nextInt(); // 重み
            mat[s][t] = mat[t][s] = w;
        }
        int src = sc.nextInt(); // スタートノード
        int dst = sc.nextInt(); // 目的地ノード
        int d = dijkstra(mat,src,dst);
        System.out.println((d==Integer.MAX_VALUE) ? "no route" : d);
    }
    public static int dijkstra(int[][] mat,int src,int dst) {
        int n = mat.length;
        int[] distance = new int[n]; // 各ノードへの最短距離
        boolean[] fixed = new boolean[n]; // 各ノードの最短距離が確定したか?
        for (int i=0; i<n; i++) { // ノードを初期化する
            distance[i] = Integer.MAX_VALUE; // 距離は無限大
            fixed[i] = false;   // 最短距離は未確定
        }
        distance[src] = 0;      // 始点ノードの距離は0
        while (true) {
            int x = minIndex(distance,fixed); // 未確定の中で最小のノード
            if (x == dst) return distance[x]; // 解を発見した
            if (x < 0 || distance[x]==Integer.MAX_VALUE) return Integer.MAX_VALUE; // 非連結グラフ
            fixed[x] = true; // ノード x までの距離は確定となる
            for (int y=0; y<n; y++) { // 各ノードに関して
                if (mat[x][y]>0 && !fixed[y]) { // xからyへエッジが存在し、yが未確定ならば
                    int d2 = distance[x]+mat[x][y];// ｘを経由したyまでの距離
                    // 今までの距離よりも小さければ、それを覚える
                    if (d2 < distance[y]) distance[y] = d2;
                }
            }
        }
    }
    // fixed[]がfalseの中で、distance[]が最小のインデックスを返す
    static int minIndex(int[] distance,boolean[] fixed) {
        int idx = -1;
        for (int i=0; i<fixed.length; i++) {
            if (!fixed[i]) // 未確定で
                if (idx < 0 || distance[idx] > distance[i]) idx = i; // 最小距離のインデックス
        }
        return idx;
    }
}
