import java.util.*;
public class Dijkstra {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in); // read from Standard Input
        int n = sc.nextInt(); // number of nodes
        int m = sc.nextInt(); // number of edges
        int[][] mat = new int[n][n]; // Adjacency matrix of node connections
        for (int i=0; i<n; i++) // initialize the matrix
            for (int j=0; j<n; j++)
                mat[i][j] = (i==j) ? 0 : -1;
        for (int i=0; i<m; i++) { // read edges
            int s = sc.nextInt(); // one node of the edge
            int t = sc.nextInt(); // another node of the edge
            int w = sc.nextInt(); // weights
            mat[s][t] = mat[t][s] = w;
        }
        int src = sc.nextInt(); // start node
        int dst = sc.nextInt(); // destination node
        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]; // shortest distance to nodes
        boolean[] fixed = new boolean[n]; // shortes distance is fixed?
        for (int i=0; i<n; i++) { // initialize nodes
            distance[i] = Integer.MAX_VALUE; // initial distance is infinity
            fixed[i] = false;   // shortest distance is unfixed
        }
        distance[src] = 0;      // distance of start node is 0
        while (true) {
            int x = minIndex(distance,fixed); // shortest node in unfixed nodes
            if (x == dst) return distance[x]; // find the answer
            if (x < 0 || distance[x]==Integer.MAX_VALUE) return Integer.MAX_VALUE; // unconnected graph
            fixed[x] = true; // node x is fixed.
            for (int y=0; y<n; y++) { // for each node
                if (mat[x][y]>0 && !fixed[y]) { // if y is directly connected with x and y is unfixed
                    int d2 = distance[x]+mat[x][y];// calculate distance of y via x
                    // if shorter, update the shortest distance of y
                    if (d2 < distance[y]) distance[y] = d2;
                }
            }
        }
    }
    // returns index of minimum distance[] whose fixed[] is false
    static int minIndex(int[] distance,boolean[] fixed) {
        int idx = -1;
        for (int i=0; i<fixed.length; i++) {
            if (!fixed[i]) // unfixed
                if (idx < 0 || distance[idx] > distance[i]) idx = i; // index of shortest node
        }
        return idx;
    }
}
