#include <bits/stdc++.h>
using namespace std;
const int N = 20;
const int T = (1 << 18) + 20;
int fa[T], ffa[T], mp[N][N], f[T], rd[N], from[T], ans[N];
int n, m, pp[T];
vector<int> G[N];
const int inf = 1e9;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y, w; i <= m; i++)
    scanf("%d%d%d", &x, &y, &w), mp[x][y] = mp[y][x] = w,
                                 fa[y] |= (1 << (x - 1)), G[x].push_back(y);
  int M = 1 << n;
  for (int i = 1; i < M; i++)
    for (int j = 1; j <= n; j++)
      if ((1 << (j - 1)) & i) {
        for (int v : G[j])
          if ((1 << (v - 1)) & i)
            ;
          else
            pp[i] += mp[j][v];
        ffa[i] |= fa[j];
      }
  for (int i = 1; i < M; i++) f[i] = inf;
  for (int i = 0; i < M - 1; i++) {
    int opp = M - 1 - i;
    for (int j = opp; j; j = opp & (j - 1))
      if ((ffa[j] & i) == ffa[j] && f[i] + pp[i] < f[i | j])
        f[i | j] = f[i] + pp[i], from[i | j] = i;
  }
  int x = M - 1, now = 1;
  while (x) {
    int y = x ^ from[x];
    for (int j = 1; j <= n; j++)
      if ((y >> (j - 1)) & 1) ans[j] = now;
    x = from[x];
    now++;
  }
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
