#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;

template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
static const ld pi = 3.141592653589793L;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

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

//グラフ関連
struct Edge {
    int to, rev;
    ll cap;
    Edge(int _to, int _rev, ll _cap) : to(_to), rev(_rev), cap(_cap) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, (int)G[to].size(), cap));
    if(revFlag)
        G[to].push_back(Edge(from, (int)G[from].size() - 1, revCap));
}

vector<ll> divisor(ll n) {
    vector<ll> ret;

    sort(ret.begin(), ret.end());
    return ret;
}
void solve() {
    ll n, m;
    cin >> n >> m;
    Graph G(n);
    vec<ll> C(m), D(m);
    REP(i, m) {
        ll a, b;
        cin >> a >> b >> C[i] >> D[i];
        a--;
        b--;
        add_edge(G, a, b, i, true, i);
    }

    vec<ll> d(n);
    REP(i, d.size())
    d[i] = INF;
    d[0] = 0;
    priority_queue<P, vector<P>, greater<P>> q;
    q.push(make_pair(0, 0));
    while(!q.empty()) {
        auto [t, v] = q.top();
        q.pop();

        if(d[v] < t)
            continue;
        for(auto e : G[v]) {
            ll cost = INF;
            chmin(cost, max(0LL, D[e.cap] - t)); //0にする
            chmin(cost, D[e.cap] / (t + 1));     //そのまま
            ll T = sqrtl(D[e.cap]);
            if(T > 1)
                chmin(cost, D[e.cap] / (T - 1) + max(0LL, T - 1 - (t + 1))); //最小の時
            if(T != 0)
                chmin(cost, D[e.cap] / T + max(0LL, T - (t + 1)));       //最小の時
            chmin(cost, D[e.cap] / (T + 1) + max(0LL, T + 1 - (t + 1))); //最小の時
            cost += C[e.cap];

            if(d[e.to] > d[v] + cost) {
                d[e.to] = d[v] + cost;
                q.push(make_pair(d[e.to], e.to));
                //cout << v << "->" << e.to << " " << d[e.to] << en;
            }
        }
    }
    if(d[n - 1] == INF)
        cout << -1 << en;
    else
        cout << d[n - 1] << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(10);

    // ll t;
    // cin >> t;
    // REP(i, t - 1) {
    //     solve();
    // }

    solve();

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;

typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
ll vx[4]={0,1,0,-1};
ll vy[4]={1,0,-1,0};
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll pow(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=pow(N,P/2,M);
        return t*t%M;
    }
    else return N*pow(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}


struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};



int main(){
    ll N,K;
    cin>>N>>K;
    ll d=2;
    ll sum=0;
    ll suma=0;
    while(sum<K){
        suma=sum;
        d++;
        if(d<=N+2){
            sum+=(d-1)*(d-2)/2;
        }
        else if(d>=2*N+1){
            sum+=(3*N+2-d)*(3*N+1-d)/2;
        }
        else {
            sum+=(d-1)*(d-2)/2;
            sum-=3*(d-N-2)*(d-N-1)/2;
        }
    }
    ll e=0;
    ll L=K-suma;
    sum=0;
    suma=0;
    while(sum<L){
        suma=sum;
        e++;
        if(d-e<N+1){
            sum+=d-e-1;
        }
        else if(d-e<=2*N){
            sum+=2*N-d+e+1;
        }
    }
    ll f,g;
    if(d-e>N+1){
        g=N-(L-suma)+1;
        f=d-e-g;
    }
    else{
        f=L-suma;
        g=d-e-f;
    }
    cout<<e<<" "<<f<<" "<<g<<endl;
}