#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define F first
#define S second
#define YES(n)cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define _GLIBCXX_DEBUG
const ll INF = 1e12;

set<pair<int,int>> st;
vector<vector<int>> graph(3000,vector<int>(0));

void dfs(int a,int b){
    st.insert(make_pair(a,b));
    for(int i=0;i<graph[b].size();i++){
        if(st.count(make_pair(a,graph[b][i]))==0){
            dfs(a,graph[b][i]);
        }
        
    }
}

int main(){
    int n,m;
    cin>>n>>m;
   
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        graph[a].push_back(b);
    }
    
    rep(i,n){
        dfs(i,i);
    }

    cout<<st.size()<<endl;
    return 0;
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define PI  3.14159265359
#define INF 100100100
#define mod 1000000007
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

const int mx = 200005;

int main(){
  int n, w;
  cin >> n >> w;
  vector<ll> d(mx);
  rep(i,n){
    int s, t, p;
    cin >> s >> t >> p;
    d[s] += p;
    d[t] -= p; 
  }
  rep(i,mx) d[i+1] += d[i];
  rep(i,mx){
    if(d[i] > w){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

