#include <bits/stdc++.h>
int n, m, x, y, z, dp[1 << 18], w[18][1 << 18], in[1 << 18], tran[1 << 18],
    v[1 << 18], a[18];
int lowbit(int x) { return x & (-x); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    x--, y--;
    w[x][1 << y] += z;
    in[1 << y] |= 1 << x;
  }
  for (int i = 0; i < n; i++)
    for (int j = 1; j < 1 << n; j++)
      w[i][j] = w[i][lowbit(j)] + w[i][j - lowbit(j)];
  for (int i = 1; i < 1 << n; i++) in[i] = in[lowbit(i)] | in[i - lowbit(i)];
  memset(dp, 0x3f, sizeof(dp));
  int all = (1 << n) - 1;
  dp[0] = 0;
  for (int i = 1; i < 1 << n; i++)
    for (int j = 0; j < n; j++)
      if (i & (1 << j)) v[i] += w[j][all ^ i];
  for (int i = 0; i < all; i++) {
    int res = all ^ i;
    for (int j = res; j; j = (j - 1) & res) {
      if ((in[j] & i) != in[j]) continue;
      if (dp[i] + v[i] < dp[i | j]) dp[i | j] = dp[i] + v[i], tran[i | j] = j;
    }
  }
  int step = 1;
  while (all) {
    int t = tran[all];
    for (int i = 0; i < n; i++)
      if (t & (1 << i)) a[i] = step;
    all ^= t;
    step++;
  }
  for (int i = 0; i < n; i++) printf("%d ", a[i]);
}
