#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8, inf = 1e9;
int n, m, type, id[1100], tp[1100];
double a[1100][1100];
void pivot(int r, int c) {
  swap(id[r + n], id[c]);
  double t = -a[r][c];
  a[r][c] = -1;
  for (int i = 0; i <= n; ++i) a[r][i] /= t;
  for (int i = 0; i <= m; ++i)
    if (a[i][c] && r != i) {
      t = a[i][c];
      a[i][c] = 0;
      for (int j = 0; j <= n; ++j) a[i][j] += t * a[r][j];
    }
}
void solve() {
  double t;
  for (int i = 1; i <= n; ++i) id[i] = i;
  while (true) {
    int i = 0, j = 0;
    double _w = -eps;
    for (int k = 1; k <= m; ++k)
      if (a[k][0] < _w) _w = a[i = k][0];
    if (!i) break;
    for (int k = 1; k <= n; ++k)
      if (a[i][k] > eps) {
        j = k;
        break;
      }
    if (!j) {
      printf("Infeasible");
      return;
    }
    pivot(i, j);
  }
  while (true) {
    int i = 0, j = 0;
    double _w = eps;
    for (int k = 1; k <= n; ++k)
      if (a[0][k] > _w) _w = a[0][j = k];
    if (!j) break;
    _w = inf;
    for (int k = 1; k <= m; ++k)
      if (a[k][j] < -eps && (t = -a[k][0] / a[k][j]) < _w) _w = t, i = k;
    if (!i) {
      printf("Unbounded");
      return;
    }
    pivot(i, j);
  }
  for (int i = n + 1; i <= n + m; ++i) tp[id[i]] = i - n;
  for (int i = 1; i <= n; ++i)
    printf("%d ", tp[i] ? (int)(a[tp[i]][0] + 0.2) : 0);
}
int nn, mm;
long long f[1000];
int main() {
  scanf("%d%d", &nn, &mm);
  for (int i = 1; i <= mm; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    f[u] += w, f[v] -= w;
    ++m;
    a[m][u] = 1, a[m][v] = -1;
    a[m][0] = -1;
  }
  for (int i = 1; i <= nn; i++) {
    a[0][i] = -f[i];
  }
  n = nn;
  solve();
}
