#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20;
const int MAXS = 1 << 19;
int inNode[MAXS];
int allOutValue[MAXS];
int value[MAXN][MAXN];
int ans[MAXN];
int dp[MAXS];
int pre[MAXS];
int rev[MAXS];
int n, m;
void getAns(int s, int val) {
  if (!s) return;
  int o = s - pre[s];
  while (o) ans[rev[o & -o]] = val, o -= o & -o;
  getAns(pre[s], val + 1);
}
int main(void) {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1, u, v, w; i <= m; ++i)
    cin >> u >> v >> w, value[u][v] = w, inNode[1 << v - 1] |= 1 << u - 1;
  for (int i = 1; i <= n; ++i) rev[1 << i - 1] = i;
  int all = (1 << n) - 1;
  for (int s = 1, u = 1, nwValue = 0, subValue = 0; s <= all;
       ++s, u = rev[s & -s], nwValue = 0, subValue = 0) {
    for (int i = 1; i <= n; ++i)
      (s & (1 << i - 1)) ? (subValue += value[i][u]) : (nwValue += value[u][i]);
    inNode[s] = inNode[s - (s & -s)] | inNode[s & -s],
    allOutValue[s] = allOutValue[s - (s & -s)] + nwValue - subValue,
    dp[s] = 2E9;
  }
  for (int s = 0, o = all; s < all; ++s, o = all - s)
    if (dp[s] != 2E9) {
      for (int s2 = o; s2; s2 = (s2 - 1) & o)
        ((inNode[s2] & s) == inNode[s2])
            ? ((dp[s + s2] > dp[s] + allOutValue[s])
                   ? (dp[s + s2] = dp[s] + allOutValue[s], pre[s + s2] = s)
                   : 0)
            : 0;
    }
  getAns(all, 1);
  for (int i = 1; i <= n; ++i) cout << ans[i] << " \n"[i == n];
  return 0;
}
