#include<bits/stdc++.h> 
using namespace std;
inline int read(){
    int res=0;
    char c;
    bool zf=0;
    while(((c=getchar())<'0'||c>'9')&&c!= '-');
    if(c=='-')zf=1;
    else res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
    if(zf)return -res;
    return res;
}
const int maxn=1e5+5;
int v[maxn];
int p[maxn],r;
int f[maxn];
signed main(){
	int n=read();
	f[1]=1;
	for(register int i=2;i<=n;++i){
		if(!v[i]){
			p[++r]=i,f[i]=2;
		}
		for(register int j=1;j<=r&&i*p[j]<=n;++j){
			v[i*p[j]]=1,f[i*p[j]]=f[i]+1;
			if(i%p[j]==0){
				break;
			}
		}
	}
	for(register int i=1;i<=n;++i){
		printf("%d ",f[i]);
	}
	puts("");
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return true; } return false;
}

int32 n,m;
vector<vector<pii>> uc;
vector<int32> ans;

void dfs(int v, int p = -1, int pc = -1, bool selected = true){
  if(selected){
    if(pc == 1){
      ans[v] = 2;
    }else{
      ans[v] = 1;
    }
  }else{
    ans[v] = pc;
  }
  for(auto [u,c] : uc[v]){
    if(ans[u] !=-1)continue;
    dfs(u,v,c,ans[v] == c);
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  uc.resize(n);
  REP(i,m){
    int32 u,v,c;
    cin >> u >> v >> c;
    --u;--v;
    uc[v].emplace_back(u,c);
    uc[u].emplace_back(v,c);
  }

  ans.resize(n,-1);
  dfs(0);
  REP(i,n)ANS(ans[i]);
  return 0;
}