using System;
using System.Collections.Generic;
using System.Security;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split();
        int n = int.Parse(s[0]);
        int m = int.Parse(s[1]);
        int[] a = new int[m];
        int[] b = new int[m];
        int[] t = new int[m];
        
        for(int i = 0; i < m; i++)
        {
            string[] ss = Console.ReadLine().Split();
            a[i] = int.Parse(ss[0]);
            b[i] = int.Parse(ss[1]);
            t[i] = int.Parse(ss[2]);
        }
        string[] sss = Console.ReadLine().Split();
        int u= int.Parse(sss[0]);
        int v = int.Parse(sss[1]);

        Console.WriteLine(-1);
    }
}