#include #include #include #include #include #include #include #include #include #include #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template void chmin(T &a,const T &b){if(a>b) a=b;} template void chmax(T &a,const T &b){if(a rank,p; vector sz; DisjointSet(){} DisjointSet(int n):N(n),rank(n),p(n),sz(n){ for(int i=0;irank[y]) swap(x,y); p[x]=y; sz[y]+=sz[x]; if(rank[x]==rank[y]){ ++rank[y]; } } int leader(int x){ if(x!=p[x]) p[x]=leader(p[x]); return p[x]; } int size(int x){ return sz[leader(x)]; } }; const int L=30; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,M; cin>>N>>M; DisjointSet us(2*N*L+2); rep(q,M){ int a,b; cin>>a>>b; a--;b--; int value; cin>>value; rep(k,L){ int lef=2*(a*L+k); int rig=2*(b*L+k); if(value>>k&1) rig^=1; us.unite(lef,rig); us.unite(lef^1,rig^1); } } rep(i,N) rep(k,L) if(us.same(2*(i*L+k),2*(i*L+k)+1)){ cout<<-1< ans(N,0); rep(i,N) rep(k,L){ int now=2*(i*L+k); if(us.same(now^1,one)) ans[i]+=(1<