#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N, M;
int S[100002];
bool is[100002];
vector<pair<int, int> > V[100002];

void go(int x)
{
    is[x] = true;
	for (vector<pair<int, int> >::iterator it = V[x].begin(); it != V[x].end(); ++it)
		if (!is[it->first])
		{
			S[it->first] = S[x] ^ it->second;
			go(it->first);
		}
}

int main()
{
	cin >> N >> M;

	for (int i = 1, pos1, pos2, val; i <= M; ++i)
	{
		cin >> pos1 >> pos2 >> val;
		V[pos1 - 1].push_back(make_pair(pos2, val));
		V[pos2].push_back(make_pair(pos1 - 1, val));
	}

	for (int i = 0; i <= N; ++i)
		if (!is[i])
			go(i);

	for (int i = 1; i <= N; ++i)
		cout << (S[i] ^ S[i - 1]) << ' ';
	cout << '\n';
}