using System;

namespace SANTE
{
    class Grana1
    {
        public int v; //vrsta
        public Grana1 sledeca;
        public Cvor1 odrediste;
        public Grana1(int v, Grana1 sledeca, Cvor1 odrediste)
        {
            this.v = v;
            this.sledeca = sledeca;
            this.odrediste = odrediste;
        }
    }
    class Cvor1
    {
        public int br;
        public int[] c = new int[2]; //cena za 0 i 1
        public Grana1 grane;
        public Cvor1 sledeci;
        public int s; //status
        public Cvor1(int br)
        {
            this.br = br;
        }
    }
    class Program
    {
        static Cvor1 pronadjiCvor(int pod, Cvor1 cvorovi)
        {
            Cvor1 cvor = cvorovi;
            while (cvor != null && !cvor.br.Equals(pod))
                cvor = cvor.sledeci;
            return cvor;
        }
        static void Main(string[] args)
        {
            string[] u = Console.ReadLine().Split();
            int n = int.Parse(u[0]);
            int m = int.Parse(u[1]);

            Cvor1 cvorovi = new Cvor1(1);
            for (int i = 2; i <= n; i++)
            {
                Cvor1 ci = cvorovi;
                while(ci.sledeci != null)
                    ci = ci.sledeci;
                ci.sledeci = new Cvor1(i);
            }
            for(int i = 0; i < m; i++)
            {
                string[] u1 = Console.ReadLine().Split();
                int a = int.Parse(u1[0]);
                int b = int.Parse(u1[1]);
                int t = int.Parse(u1[2]);

                Cvor1 polazni = pronadjiCvor(a,cvorovi);
                Cvor1 dolazni = pronadjiCvor(b,cvorovi);
                Grana1 g = new Grana1(t, polazni.grane, dolazni);
                polazni.grane = g;
                Grana1 g1 = new Grana1(t, dolazni.grane, polazni);
                dolazni.grane = g1;
            }

            string[] u2 = Console.ReadLine().Split();
            Cvor1 mika = pronadjiCvor(int.Parse(u2[0]),cvorovi);
            Cvor1 laza = pronadjiCvor(int.Parse(u2[1]),cvorovi);
            Cvor1 trazi = mika;
        }
    }
}