#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<pair<int, int>>> ind, out;
vector<int> can, ch;
vector<long long> cost, dp;
bool can_go(int mask, int sub) {
  bool v1 = ((~mask & ~can[sub]) & ((1 << n) - 1)) == 0;
  bool v2 = (sub & can[sub]) == sub;
  return v1 && v2;
}
int main() {
  scanf("%d%d", &n, &m);
  ind.assign(n, vector<pair<int, int>>());
  out.assign(n, vector<pair<int, int>>());
  for (int i = 0; i < m; ++i) {
    int x, y, w;
    cin >> x >> y >> w;
    out[x - 1].push_back({y - 1, w});
    ind[y - 1].push_back({x - 1, w});
  }
  can.assign(1 << n, (1 << n) - 1);
  cost.assign(1 << n, 0);
  for (int mask = 0; mask < can.size(); ++mask) {
    for (int i = 0; i < n; ++i) {
      if (mask & (1 << i)) {
        for (auto &x : out[i]) {
          cost[mask] += x.second;
        }
        for (auto &x : ind[i]) {
          if (can[mask] & (1 << x.first)) {
            can[mask] ^= (1 << x.first);
          }
          cost[mask] -= x.second;
        }
      }
    }
  }
  dp.assign(1 << n, ((long long)1e18 + 10));
  ch.assign(1 << n, -1);
  dp[0] = 0;
  for (int mask = 1; mask < (1 << n); ++mask) {
    for (int sub = mask; sub > 0; sub = (sub - 1) & mask) {
      if (can_go(mask, sub)) {
        long long v1 = dp[mask ^ sub];
        long long v2 = cost[mask ^ sub] + cost[sub];
        if (v1 + v2 < dp[mask]) {
          dp[mask] = v1 + v2;
          ch[mask] = sub;
        }
      }
    }
  }
  vector<int> ans(n);
  for (int mask = (1 << n) - 1, z = 0; mask > 0; ++z) {
    int sub = ch[mask];
    for (int i = 0; i < n; ++i) {
      if (sub & (1 << i)) {
        ans[i] = z;
      }
    }
    mask ^= sub;
  }
  for (int x : ans) printf("%d ", x);
  printf("\n");
}
