#include <bits/stdc++.h>
int main() {
  static int ww[18], adj[18], ww_[1 << 18], dp[1 << 18], bb_[1 << 18], aa[18];
  int n, m, i, j, b;
  scanf("%d%d", &n, &m);
  while (m--) {
    int w;
    scanf("%d%d%d", &i, &j, &w), i--, j--;
    ww[i] += w, ww[j] -= w;
    adj[i] |= 1 << j;
  }
  for (i = 0; i < n; i++) ww_[1 << i] = ww[i];
  for (b = 0; b < 1 << n; b++) ww_[b] = ww_[b & b - 1] + ww_[b & -b];
  memset(dp, 0x3f, (1 << n) * sizeof *dp), dp[0] = 0;
  for (b = 0; b < 1 << n; b++) {
    int x, c, b_;
    x = dp[b] + ww_[b];
    c = (1 << n) - 1 ^ b;
    for (i = 0; i < n; i++)
      if ((b & 1 << i) == 0) c &= ~adj[i];
    b_ = 0;
    do
      if (dp[b ^ b_] > x) dp[b ^ b_] = x, bb_[b ^ b_] = b;
    while (b_ = b_ - c & c);
  }
  b = (1 << n) - 1;
  while (b = bb_[b])
    for (i = 0; i < n; i++)
      if ((b & 1 << i) != 0) aa[i]++;
  for (i = 0; i < n; i++) printf("%d ", aa[i]);
  printf("\n");
  return 0;
}
