#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAX_N=1e6+10; 
ll n,k;
ll dp[4][MAX_N*3];
ll sum[MAX_N*3];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) dp[1][i]=1;
	for(int i=2;i<=3;i++){
		sum[0]=0;
		for(int j=1;j<=i*n;j++) sum[j]=sum[j-1]+dp[i-1][j];
		for(int j=1;j<=i*n;j++) dp[i][j]=sum[j-1]-sum[max(0ll,j-n-1)];
	}
	int tmp=1;
	while(k-dp[3][tmp]>0) k-=dp[3][tmp++];
	ll ans1=1;
	while(k-dp[2][tmp-ans1]>0) k-=dp[2][tmp-ans1++];
	tmp-=ans1;
	ll mn=max(1ll,tmp-n),ans2=mn+k-1,ans3=tmp-ans2;
	printf("%lld %lld %lld\n",ans1,ans2,ans3);


	
    return 0;
}
#line 1 "/Users/lynmisakura/kyopro/library_cp/template.cpp"
#include<bits/stdc++.h>
#line 3 "/Users/lynmisakura/kyopro/library_cp/template.cpp"
using namespace std;
#define REP(i,n) for(int i = 0;i < n;i++)
#define RNG(i,s,n) for(int i = s;i <= n;i++)
#define _RNG(i,e,s) for(int i = e;i >= s;i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define dup(x,y) (x + y - 1) / (y)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define lb(x,key) lower_bound(all(x) , (key))
#define ub(x,key) upper_bound(all(x) , (key))
#define _size(v) int((v).size())

template<class T> bool chmax(T& a,T b){ if(a < b){ a = b; return true; }else return false; }
template<class T> bool chmin(T& a,T b){ if(a > b){ a = b; return true; }else return false; }

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;

#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n"
#define debug3(a,b,c) cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n"
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
    cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
    return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
    cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
    return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
    cout << "{" << p.first << "," << p.second << "}" << '\n';
    return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
    for (auto& i : arr)cin >> i; return in;
}
template<class S,class T> istream &operator >> (istream& in,pair<S,T>& p){
    cin >> p.first >> p.second; return in;
}

#define F first
#define S second
/////////////////////////////////////////////////////////////////////////
namespace cp{
    void iob(){ cin.tie(0); ios::sync_with_stdio(false); }
}
#line 2 "main.cpp"
// =========================== DIJKSTRA's SHORTEST PATH ===============================
namespace cp{
using std::vector;
using std::pair;
    template<class T> struct Dijkstra{
	using P = pair<T,int>;
	int N;
	std::vector<std::vector<P>> graph;
	Dijkstra(){}
	Dijkstra(int N):N(N){graph.resize(N);}
	void add_edge(int a,int b){ add_edge(a,b,1); }
	void add_edge(int a,int b,T c){ graph[a].emplace_back(c,b); }
	const T INF=std::numeric_limits<T>::max()/2;
	vector<T> dist;
	vector<int> prev,vis;
	void solve(int s){
	    dist.assign(N,INF);
	    prev.assign(N,-1);
	    vis.assign(N,0);
	    dist[s]=0,vis[s]=1;
	    std::priority_queue<P,vector<P>,std::greater<P>> Q;
	    Q.push({0,s});
	    while(!Q.empty()){
		auto[d,v]=Q.top();Q.pop();
		vis[v]=1;
		if(dist[v]<d)continue;
		for(auto& [c,to] : graph[v]){
		    if(dist[to]>dist[v]+c){
			dist[to]=dist[v]+c;
			prev[to]=v;
			Q.push({dist[to],to});
		    }
		}
	    }
	}
	vector<int> get_path(int to){
	    vector<int> res;
	    while(to!=-1){ res.push_back(to); to=prev[to]; }
	    reverse(res.begin(),res.end());
	    return res;
	}
	bool reachable(int x){ return vis[x]; }
    };
};

ll mindist[2020][2020];

int main(){

    int n,m;cin >> n >> m;
    
    REP(i,2020)REP(j,2020) mindist[i][j] = (1LL << 55);

    cp::Dijkstra<ll> graph(2 * n);    
    
    REP(i,m){
	int a,b;cin >> a >> b;
	a--,b--;
	ll c;cin >> c;
	chmin(mindist[a][b],c);
	graph.add_edge(a,b,c);
    }
    
    for(int i = n;i < 2 * n;i++){
	for(int j = 0;j < n;j++){
	    if(mindist[i - n][j] == (1LL << 55))continue;
	    graph.add_edge(i,j,mindist[i - n][j]);
	}
    }
    
    for(int i = n;i < 2 * n;i++){
	graph.solve(i);
	if(graph.reachable(i - n)){
	    cout << graph.dist[i-n] << '\n';
	}else{
	    cout << -1 << '\n';
	}
    }

}
