#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cout << *x, 0);
template <class c>
char dud(...);
struct debug {
  ~debug() { cout << '\n'; }
  template <class c>
  typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
    cout << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class c, class b>
  debug& operator<<(pair<b, c> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }
  template <class c>
  debug& operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
};
typedef double T;
const T eps = 1e-8, inf = 1 / .0;
struct LPSolver {
  int m, n;
  vector<long long int> N, B;
  vector<vector<T>> D;
  LPSolver(const vector<vector<T>>& A, const vector<T>& b, const vector<T>& c)
      : m((int)b.size()),
        n((int)c.size()),
        N(n + 1),
        B(m),
        D(m + 2, vector<T>(n + 2)) {
    for (int i = 0; i < m; i++)
      for (int j = 0; j < n; j++) D[i][j] = A[i][j];
    for (int i = 0; i < m; i++) {
      B[i] = n + i;
      D[i][n] = -1;
      D[i][n + 1] = b[i];
    }
    for (int j = 0; j < n; j++) {
      N[j] = j;
      D[m][j] = -c[j];
    }
    N[n] = -1;
    D[m + 1][n] = 1;
  }
  void pivot(int r, int s) {
    T *a = D[r].data(), inv = 1 / a[s];
    for (int i = 0; i < m + 2; i++)
      if (i != r && abs(D[i][s]) > eps) {
        T *b = D[i].data(), inv2 = b[s] * inv;
        for (int j = 0; j < n + 2; j++) b[j] -= a[j] * inv2;
        b[s] = a[s] * inv2;
      }
    for (int j = 0; j < n + 2; j++)
      if (j != s) D[r][j] *= inv;
    for (int i = 0; i < m + 2; i++)
      if (i != r) D[i][s] *= -inv;
    D[r][s] = inv;
    swap(B[r], N[s]);
  }
  bool simplex(int phase) {
    int x = m + phase - 1;
    for (;;) {
      int s = -1;
      for (int j = 0; j < n + 1; j++)
        if (N[j] != -phase)
          if (s == -1 || make_pair(D[x][j], N[j]) < make_pair(D[x][s], N[s]))
            s = j;
      if (D[x][s] >= -eps) return true;
      int r = -1;
      for (int i = 0; i < m; i++) {
        if (D[i][s] <= eps) continue;
        if (r == -1 || make_pair(D[i][n + 1] / D[i][s], B[i]) <
                           make_pair(D[r][n + 1] / D[r][s], B[r]))
          r = i;
      }
      if (r == -1) return false;
      pivot(r, s);
    }
  }
  T solve(vector<T>& x) {
    int r = 0;
    for (int i = 1; i < m; i++)
      if (D[i][n + 1] < D[r][n + 1]) r = i;
    if (D[r][n + 1] < -eps) {
      pivot(r, n);
      if (!simplex(2) || D[m + 1][n + 1] < -eps) return -inf;
      for (int i = 0; i < m; i++)
        if (B[i] == -1) {
          int s = 0;
          for (int j = 1; j < n + 1; j++)
            if (s == -1 || make_pair(D[i][j], N[j]) < make_pair(D[i][s], N[s]))
              s = j;
          pivot(i, s);
        }
    }
    bool ok = simplex(1);
    x = vector<T>(n);
    for (int i = 0; i < m; i++)
      if (B[i] < n) x[B[i]] = D[i][n + 1];
    return ok ? D[m][n + 1] : inf;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long int n, m;
    cin >> n >> m;
    vector<pair<pair<long long int, long long int>, long long int>> edges(m);
    for (long long int i = 0; i < m; i++) {
      cin >> edges[i].first.first >> edges[i].first.second >> edges[i].second;
      edges[i].first.first--;
      edges[i].first.second--;
    }
    vector<vector<T>> A;
    vector<T> b;
    for (auto it : edges) {
      vector<T> tmp(n, 0);
      tmp[it.first.first] = -1.0;
      tmp[it.first.second] = +1.0;
      A.push_back(tmp);
      b.push_back(-1.0);
    }
    vector<T> c(n, 0);
    for (auto it : edges) {
      c[it.first.first] -= it.second;
      c[it.first.second] += it.second;
    }
    vector<T> x;
    LPSolver(A, b, c).solve(x);
    for (auto it : x) {
      long long int ai = (long long int)(it + 0.5);
      cout << ai << " ";
    }
    cout << '\n';
  }
  return 0;
}
