using System;

    internal class Program
    {
        static void Promena(bool stanje, int k)
        {
            stanje = !stanje;
            k++;
        }
        static void Main(string[] args)
        {
            int k = 0;
            bool stanje = false;
            string[] str = Console.ReadLine().Split(' ');
            int n = int.Parse(str[0]);
            int m = int.Parse(str[1]);
            int[] a = new int[m];
            int[] b = new int[m];
            int[] t = new int[m];

            for(int i = 0; i< m; i++)
            {
                string[] str2 = Console.ReadLine().Split(" ");
                a[i] = int.Parse(str2[0]);
                b[i] = int.Parse(str2[1]);
                t[i] = int.Parse(str2[2]);
            }

            str = Console.ReadLine().Split(" ");
            int u = int.Parse(str[0]);
            int v = int.Parse(str[1]);

            int mika = -1;
            int laza = b[0];


            for (int i = 0; i < m; i++)
            {
                if (a[i] == u)
                    mika = a[i];

                if (b[i] < laza)
                    laza = b[i];

                if (v != laza)
                {
                    Promena(stanje, k);
                }
            }
        }
    }