#include <bits/stdc++.h>
using namespace std;
const int N = 18;
bool chosen[N][N][1 << N];
int sum[1 << N];
int ans[N];
vector<int> order;
bool visited[N];
int coeff[N];
int adj[N];
int n;
void dfs(int u) {
  if (!visited[u]) {
    visited[u] = true;
    for (int c = 0; c < n; ++c) {
      if ((adj[u] & (1 << c)) > 0) {
        dfs(c);
      }
    }
    order.insert(order.begin(), u);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    coeff[--u] += w;
    coeff[--v] -= w;
    adj[u] |= 1 << v;
  }
  for (int i = 0; i < n; ++i) {
    dfs(i);
  }
  fill(sum, sum + (1 << n), INT_MAX);
  sum[0] = 0;
  for (int i = 0; i < n; ++i) {
    for (auto j : order) {
      for (int k = 0; k < (1 << n); ++k) {
        if (sum[k] != INT_MAX && (k & adj[j]) == adj[j] &&
            (k & (1 << j)) == 0) {
          int k_new = k ^ (1 << j);
          if (sum[k] + i * coeff[j] < sum[k_new]) {
            sum[k_new] = sum[k] + i * coeff[j];
            chosen[i][j][k_new] = true;
          }
        }
      }
    }
  }
  reverse(order.begin(), order.end());
  int mask = (1 << n) - 1;
  for (int i = n - 1; i >= 0; --i) {
    for (auto j : order) {
      if (chosen[i][j][mask]) {
        mask ^= 1 << j;
        ans[j] = i;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << " ";
  }
  cout << "\n";
}
