#include <iostream>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[m];
    int b[m];
    int t[m];
    bool l=true;
    for (int i=0; i<m; ++i){
        cin>>a[i]>>b[i]>>t[i];
        if (t[i]==0){l=false;}
    }
    int u,v;
    cin>>u>>v;
    if (l){
        cout<<1;
    }
    else{
        cout<<n/2;
    }
    return 0;
}