#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<string.h>
#include<array>
#include<algorithm>
#include<cmath>
#define ff first
#define ss second
#define endl '\n'
#define int long long
const int maxn = 5e5;
const int oo = 1e18;
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
int m1 = m;
vector<int> T(n);
while(m1--){
int x, y, z;
cin >> x >> y >> z;
T[x - 1] = max(T[x - 1], z);
T[y - 1] = max(T[y - 1], z);
}
int cur = 1;
for(int i = 0; i < n; i++){
if(T[i] == 0){
T[i] = cur++;
}
}
for(int i = 0; i < n; i++){
cout << T[i] << " ";
}
}