#include <iostream>

using namespace std;

int main()
{
    unsigned int n, m, a, b, i, u, v;
    bool t, k = 0;
    cin >> n >> m;
    for ( i = 0; i < m; i ++ )
    {
        cin >> a >>  b >> t;
        if ( t == 0 )
            k = 1;
    }
    cin >> u >> v;
    if ( k == 0 )
        cout << 1;
    return 0;
}