n, m = map(int, input().split())
dp = [[0x7fffffff] * (2*n+1) for _ in range(2*n+1)]
dis = [[0x7fffffff] * (2*n+1) for _ in range(2*n+1)]
path = {}
for i in range(1, n+1):
path[(i, i)] = [i]
edges = []
all_nodes = set()
for i in range(m):
a, b, w = map(int, input().split())
edges.append((a, b, w))
all_nodes.add(a)
all_nodes.add(b)
all_nodes = list(all_nodes)
idx2node = {}
node2idx = {}
for i, node in enumerate(all_nodes):
idx2node[i+1] = node
node2idx[node] = i+1
for a, b, w in edges:
a, b = node2idx[a], node2idx[b]
dp[a][b] = w
dp[b][a] = w
dis[a][b] = w
dis[b][a] = w
path[(a, b)] = [a, b]
path[(b, a)] = [b, a]
n = len(all_nodes)
for i in range(1, n+1):
dp[i][i] = 0
dis[i][i] = 0
min_cycle_len = 0x7fffffff
min_cycle = None
'''
Floyd算法求最小环,把所有环分成n类,最大节点编号是1的, 最大节点编号是2的 ..... 最大节点编号是n的 总共n类,每一类求长度最小值,
然后再求所有最小值的最小值,就是答案
其中最大节点编号是k的环,一定是两个小于k的数i, j, i 和 k直连, j和k直连,然后i j之前经过编号小于k的点连起来,并且连接的路径是最短的
这正好和Floyd第k轮开始迭代开始前的状态一样,只需要在第k轮迭代开始前,枚举所有id小于k的点对i, j 看i, j, k能不能形成更小的环即可,Floyd
算法迭代时候,需要同时维护距离和路径
'''
for k in range(1, n+1):
for i in range(1, k):
for j in range(1, k):
if i == j:
continue
if dp[i][j] + dis[i][k] + dis[k][j] < min_cycle_len:
min_cycle_len = dp[i][j] + dis[i][k] + dis[k][j]
min_cycle = [k] + path[(i, j)]
for i in range(1, n+1):
for j in range(1, n+1):
if dp[i][k] + dp[k][j] < dp[i][j]:
dp[i][j] = dp[i][k] + dp[k][j]
path[(i, j)] = path[(i, k)] + path[(k, j)][1:]
if min_cycle_len == 0x7fffffff:
print('No solution.')
else:
min_cycle = [idx2node[idx] for idx in min_cycle]
print( ' '.join(map(str, min_cycle)) )