#include <bits/stdc++.h>
using namespace std;
int reachable[1000000], fth[1000000], a[20], sol[20];
long long dp[1000000], cost[1000000], sum[20];
int n, m, x, y, i, cst;
int main() {
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> cst;
    x--, y--;
    sum[x] += cst;
    sum[y] -= cst;
    a[y] |= (1 << x);
  }
  for (int mask = 0; mask < (1 << n); mask++) {
    dp[mask] = 2000000000000000000LL;
    for (int i = 0; i < n; i++)
      if (mask & (1 << i)) {
        reachable[mask] |= a[i];
        cost[mask] += sum[i];
      }
  }
  for (int mask = 0; mask < (1 << n); mask++) {
    if (!reachable[mask]) {
      fth[mask] = mask;
      dp[mask] = 0;
    }
    for (int mask2 = mask; mask2 > 0; mask2 = ((mask2 - 1) & mask)) {
      if (reachable[mask2] == ((mask ^ mask2) & reachable[mask2])) {
        if (dp[mask ^ mask2] + cost[mask ^ mask2] < dp[mask]) {
          dp[mask] = dp[mask ^ mask2] + cost[mask ^ mask2];
          fth[mask] = mask2;
        }
      }
    }
  }
  int mask = (1 << n) - 1, idx = 0;
  while (mask > 0) {
    int mask2 = fth[mask];
    for (i = 0; i < n; i++)
      if (mask2 & (1 << i)) sol[i] = idx;
    mask ^= mask2;
    idx++;
  }
  for (i = 0; i < n; i++) cout << sol[i] << " ";
  return 0;
}
