#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define oo 1000000010
const int N = 200010;
int n , m;

vector< pair< int , int > > g[N];

long long cost[N][2][2];


int main(){
	scanf("%d%d",&n,&m);
	for(int u , v , w , i = 0 ;i < m;i++){
		scanf("%d%d%d",&u,&v,&w);
		g[u].push_back(make_pair(v , w));
		g[v].push_back(make_pair(u , w));
	}
	memset(cost,-1,sizeof(cost));
	priority_queue < pair< long long , pair< int , pair < int , int > > > > q;
	q.push(make_pair(0 , make_pair(1 , make_pair(0 , 0))));
	int node ;
	long long c;
	int a , b;
	while(!q.empty()){
		c = -q.top().first;
		node = q.top().second.first;
		a = q.top().second.second.first;
		b = q.top().second.second.second;
		q.pop();
		if(cost[node][a][b] != -1) 
			continue;
		cost[node][a][b] = c;
		for(int i = 0 ;i < (int)g[node].size();i++){
			if(cost[g[node][i].first][a][b] == -1)
				q.push(make_pair(-(c + g[node][i].second) , make_pair(g[node][i].first , make_pair(a , b))));
			if(!a && cost[g[node][i].first][1][b] == -1)
				q.push(make_pair(-c , make_pair(g[node][i].first , make_pair(1 , b))));
			if(!b && cost[g[node][i].first][a][1] == -1)
				q.push(make_pair(-(c + 2LL * g[node][i].second), make_pair(g[node][i].first , make_pair(a , 1))));
			if(!b && !a && cost[g[node][i].first][1][1] == -1)
				q.push(make_pair(-(c + g[node][i].second), make_pair(g[node][i].first , make_pair(1 , 1))));
		}
	}
	for(int i = 2;i <= n;i++){
		if(i > 2) putchar(' ');
		printf("%lld",cost[i][1][1]);
	}
	puts("");
	return 0;
}