// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2e5;
struct muchie {
int x, y, c;
};
muchie e[NMAX + 1];
int dist[NMAX + 1];
int main() {
freopen("bellmanford.in", "r", stdin);
freopen("bellmanford.out", "w", stdout);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> e[i].x >> e[i].y >> e[i].c;
}
for (int i = 1; i <= n; i++) {
dist[i] = 1e9;
}
dist[1] = 0;
for (int i = 1; i <= n - 1; i++) {
for (int j = 1; j <= m; j++) {
if (dist[e[j].y] > dist[e[j].x] + e[j].c) {
dist[e[j].y] = dist[e[j].x] + e[j].c;
//cout << "Ciclu negativ";
//return 0;
}
}
}
for (int i = 1; i <= m; i++) {
if (dist[e[i].y] > dist[e[i].x] + e[i].c) {
cout << "Ciclu negativ!";
return 0;
}
}
for (int i = 2; i <= n; i++) {
cout << dist[i] << " ";
}
}