#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FIO                     ios::sync_with_stdio(false); cin.tie(nullptr)
#define TC(t)                   int t; cin >> t; for(int i = 1; i <= t; i++)
#define deb(x)                  cerr << #x << " = " << x << endl
#define deb2(x, y)              cerr << #x << " = " << x << ", " << #y << " = " << y << endl
#define f0(i, a, n)             for(i = a; i < n; i++)
#define f1(i, a, n)             for(i = a; i <= n; i++)
#define ini(x, y)               memset(x, y, sizeof(x))
#define all(x)                  x.begin(), x.end()
#define sz(x)                   x.size()
#define ll                      long long int
#define pb                      push_back
#define ppb                     pop_back
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define M                       1000000007
#define endl                    '\n'
#define bits(x)                 __builtin_popcountll(x)
#define zrbits(x)               __builtin_ctzll(x)
#define vi                      vector<int>
#define pii                     pair<int,int>
#define vpii                    vector<pii>
#define ordered_set             tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define multi_ordered_set       tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>

const int N = 1e5 + 1;
const int MX = 1e9;
const ll INF = 1e18;

using namespace std;
using namespace __gnu_pbds;

inline ll uceil(ll a,ll b) {return (a % b ? a / b + 1 : a / b);}
inline ll mod(ll x) {return ( (x % M + M) % M );}

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {for(auto& x : v) os << x << " "; return os << '\n';}
template<typename... T> void in(T&... args) {((cin >> args), ...);}
template<typename... T> void out(T&&... args) {((cout << args << endl), ...);}
template<typename... T> void out2(T&&... args) {((cout << args << " "), ...);}

void solve() {
        ll n, w, i, j;
        cin >> n >> w;
        
        vector<pair<ll,ll>> v;
        f0(i, 0, n) {
                ll x, y, c;
                cin >> x >> y >> c;
                v.pb({x,c});
                v.pb({y,-c});
        }
        sort(all(v));

        ll sum = 0;
        for(auto it : v) {
                sum += (it.ss);
                if(sum > w) {
                        out("No");
                        return;
                }
                if(sum < 0) sum = 0;
        }
        out("Yes");
}

int main () {
        FIO;
        // TC(t)
        solve();
        return 0;
}
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long  long ll;
const ll MAX = 1e18 + 100;
const int maxN = 1e5 + 5;
const int maxM = 2e5 + 5;
ll head[maxN], cnt;
struct edge {
	ll c, d;
	ll to, best_time, next;
}e[maxM];
ll n, m, dis[maxN];
void add_e(ll x, ll y, ll val_t, ll c, ll d)
{
	e[++cnt].to = y;
	e[cnt].best_time = val_t;
	e[cnt].c = c; e[cnt].d = d;
	e[cnt].next = head[x];
//	cout<<x<<' '<<head[x]<<endl;
	head[x] = cnt;
//	printf("cnt=%d\n",cnt);
//	cout<<x<<' '<<head[x]<<endl<<endl;
}
struct node {
	ll time, dis, pos;
	bool operator < (const node& a)const {
		return dis > a.dis;
	}
}t;
void dij()
{
	int i;
	priority_queue<node>qu;
	dis[1] = 0;
	qu.push(node{ 0, 0, 1 });
	while (!qu.empty())
	{
		t = qu.top(); qu.pop();
		int now = t.pos;
		if (dis[now] != t.dis) continue;
		for (i = head[now]; i; i = e[i].next)
		{
			int To = e[i].to;
			if (t.time < e[i].best_time)
			{//要等待时间 
				int minn_dis = e[i].c + (ll)(e[i].d / (e[i].best_time + 1));
			
				if (dis[To] > dis[now] + minn_dis + e[i].best_time - t.time)
				{
					dis[To] = dis[now] + minn_dis + e[i].best_time - t.time;
					qu.push(node{ dis[To], dis[To], To });
				}
			}
			else
			{//不用等待时间 
				int minn_dis = e[i].c + (ll)(e[i].d / (t.time + 1));
				if (dis[To] > dis[now] + minn_dis)
				{
					dis[To] = dis[now] + minn_dis;
					qu.push(node{ dis[To], dis[To], To });
				}	
			}
		}
	}
}
int main()
{
	int i, j;
	ll x, y;
	ll c, d;
	cin >> n >> m;
	for (i = 0; i < m; i++)
	{
		cin >> x >> y >> c >> d;
		if (x == y)continue;
		ll minn = MAX, tt;
		double pos = sqrt(d);
		for (j = (int)pos - 2; j <= (int)pos + 2; j++)
			if (j >= 0)
				if (minn > (c + (int)(d / (j + 1)) + j))
				{
					minn = c + (int)(d / (j + 1)) + j;
					tt = j;
				}
		add_e(x, y, tt, c, d);
		add_e(y, x, tt, c, d);
	}
	for (i = 1; i <= n; i++)
		dis[i] = MAX;
	dij();
	if (dis[n] == MAX)
		cout << -1 << endl;
	else
		cout << dis[n] << endl;
	return 0;
}