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

using namespace std;

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

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));
	}
	
	is[0] = true;
	for (int i = 0; i <= N; ++i)
	{
		if (!is[i])
		{
			for (vector<pair<int, int> >::iterator it = V[i].begin(); it != V[i].end(); ++it)
				if (is[it->first])
				{
					S[i] = S[it->first] ^ it->second;
					break;
				}
			
			is[i] = true;
		}
		for (vector<pair<int, int> >::iterator it = V[i].begin(); it != V[i].end(); ++it)
			if (!is[it->first])
			{
				S[it->first] = S[i] ^ it->second;
				is[it->first] = true;
			}
	}
	
	for (int i = 1; i <= N; ++i)
		cout << (S[i] ^ S[i - 1]) << ' ';
	cout << '\n';
}