#include<bits/stdc++.h>

using namespace std ;
vector<vector<int>> put ;
class Graph{
    int V ;
    list<int>* adj ;
    void printAllPathsUtil(int, int, bool[], int[], int&);
    public:
    Graph(int V);
    void addEdge(int u, int v);
    void printAllPaths(int s, int d);


};
Graph::Graph(int V)
{
    this->V = V;
    adj = new list<int>[V];

}
void Graph::addEdge(int u, int v)
{
    adj[u].push_back(v);
}
void Graph::printAllPaths(int s, int d)
{
    bool* visited = new bool[V];
    int* path = new int[V];
    int path_index = 0;
    for (int i = 0; i < V; i++)
        visited[i] = false;
    printAllPathsUtil(s, d, visited, path, path_index);
}
void Graph::printAllPathsUtil(int u, int d, bool visited[],int path[], int& path_index)
{
    visited[u] = true;
    path[path_index] = u;
    path_index++;
    vector<int> p ;
    if(u == d){
        for (int i = 0; i < path_index; i++)
             p.push_back(path[i]);
        put.push_back(p) ;
    }
    else{
        list<int>::iterator i;
        for (i = adj[u].begin(); i != adj[u].end(); ++i)
            if (!visited[*i])
                printAllPathsUtil(*i, d, visited, path,path_index);
    }
    path_index--;
    visited[u] = false;
}
int main(){
    int n ;
    int m ;
    cin >> n ;
    cin >> m ;
    Graph g(n) ;
    int a, b, t ;
    vector<int> gr[n] ;
    vector<int>type[n] ;
    for(int i=0; i<m ; i++){
        cin >>a >> b>> t ;
        gr[a].push_back(b) ;
        gr[b].push_back(a) ;
        type[a].push_back(t) ;
        type[b].push_back(t) ;
        g.addEdge(a,b) ;
    }
    cin >> a >> b ;
    g.printAllPaths(a, b);
    int d=put.size() ;
    int ts=0 ;
    int uk=0 ;
    int mn=100000000 ;
    for(int i=0 ; i<n ; i++){
        for(int j=1; j<put[i].size() ; j++){
            int in=lower_bound(gr[put[i][j-1]].begin(),gr[put[i][j-1]].end(),j)-gr[put[i][j-1]].begin()+1 ;
            if(type[put[i][j-1]][in]!=ts){
                ts=type[put[i][j-1]][in] ;
                uk++ ;
            }
            if(uk<mn){
                mn=uk ;
            }

        }
    }
    cout << uk ;

}