#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<ll>
#define vii vector<pii>
#define vvi vector<vector<int>>
#define mi  map<int,int>
#define mii map<pii,int>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
// #define mp make_pair
#define sz(x) (int)x.size()
#define all(v) (v).begin(), (v).end()
#define ret(x) return cout<<x,0;
#define rety return cout<<"YES",0;
#define retn return cout<<"NO",0;
#define fl fflush(stdout)   
#define hell 1000000007
#define hell2 998244353 
#define pi 3.14159265358979323846
 
int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=ans*a%m; b/=2;a=a*a%m;}return ans;}
int inverse(int a, int p){return fexp(a, p-2,p);} 
 
int fac[300005]; //fac[0]=0;fac[1]=1;rep(i,2,300005)fac[i]=(fac[i-1]+fac[i-2])%hell;
 
int ncr(int n, int r,int p) { 
    if (r==0) return 1; 
    return (fac[n]*inverse(fac[r],p)%p*inverse(fac[n-r],p)%p)%p; 
}
void code_hunter(){
    ll n,m;cin>>n>>m;
    cout<<n/m;
}
 signed main(){
    IOS;
    int t=1;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // cin>>t;
    while(t--){
        code_hunter();
       // cout<<"\n";
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr long long INF = 1e9+10;
constexpr long long LINF = 1e18+10;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct edge{
    int from;
    int to;
    int c;
};

int main(){
    int n, m; cin >> n >> m;
    vector<vector<edge>> G(n+10);
    rep(i, m){
        int u, v, c; cin >> u >> v >> c;
        edge e1{u,v,c};
        edge e2{v,u,c};
        G[u].push_back(e1);
        G[v].push_back(e2);
    }
    //始点＝頂点0としてBFS
    vector<int> ans(n+10, INF);//頂点に振る番号
    queue<pii> que; //頂点番号,ラベル
    que.push({1, INF});//-1
    while(!que.empty()){
        auto p = que.front(); que.pop();
        int v = p.first, c = p.second; //一致なら正、不一致なら負
        //cout << "v:" << v << " c:" << c << ln;
        if(ans[v]!=INF)continue;
        if(c==INF)ans[v] = 1;
        else{
            if(c>0){
                ans[v] = (c == 1 ? 2 : 1);
            }else{
                c = -c;
                ans[v] = c;
            }     
        }
        for(auto e: G[v]){
            if(ans[e.to]!=INF)continue;
            int nc = e.c;
            if(ans[v]!=nc) nc = -e.c;
            que.push({e.to, nc});
        }
    }

    for(int i=1; i<=n; i++){
        cout << ans[i] << ln;
    }

}
