#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
//bool vis[1000];
//int x[]={1,-1,0,0};
//int y[]={0,0,1,-1};
//int f=0;
//int t[500000];
//int ll[500000];
//"'';

   int main(){
     ll n,w;
     cin>>n>>w;
     vector<ll> v(300000,0);
     for(int i=0;i<n;i++){
        ll a,b,p;
        cin>>a>>b>>p;
        v[a]+=p;
        v[b]-=p;
     }
     int f=0;
     if(v[0]>w){
        f=1;
     }
     for(int i=1;i<300000;i++){
            v[i]+=v[i-1];
        if(v[i]>w){
        f=1;
     break;
     }
     }
     if(f==0){
        cout<<"Yes";
     }
     else{
        cout<<"No";
     }

   }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ULL;
#define endl "\n"
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
void read(vector<int> &a, int n) {for (int i = 0; i < n; i++)cin >> a[i];}
void read(vector<ll> &a, int n) {for (int i = 0; i < n; i++)cin >> a[i];}
const int MOD = 1e9 + 7;
const int INF = (int)2e9 + 7;
const ll LINF = (ll)1e18;
const ld PI = 3.1415926535897932384626433832795;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int calc(string s1, string s2) {
    string s3 = s1;
    vector<int> z;
    int n = s1.size();
    for (int i = 0; i < n; i++) {
        if (s1[i] == '0') {
            z.pb(i);
        }
    }
    reverse(all(z));
    int ans = INF, cnt = 0;
    for (int i = 0; i < n; i++) {
        if (s1[i] == '0') {
            z.pop_back();
        }
        if (s1[i] == s2[i]) {
            continue;
        }
        if (s1[i] == '1' && s2[i] == '0') {
            if (i == n - 1 || z.size() == 0) {
                continue;
            }
            swap(s1[i], s1[z.back()]);
            z.pop_back();
            cnt++;
        }
    }
    bool ok = 1;
    for (int i = 0; i < n; i++) {
        if (s1[i] != s2[i]) {
            ok = 0;
        }
    }
    if (ok) {
        ans = cnt;
    }
    z.clear();
    for (int i = 0; i < n; i++) {
        if (s3[i] == '0') {
            z.pb(i);
        }
    }
    cnt = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (s3[i] == '0') {
            z.pop_back();
        }
        if (s3[i] == s2[i]) {
            continue;
        }
        if (s3[i] == '1' && s2[i] == '0') {
            cnt++;
            if (i == 0 || z.size() == 0) {
                continue;
            }
            swap(s3[i], s3[z.back()]);
            z.pop_back();
        }
    }
    ok = 1;
    for (int i = 0; i < n; i++) {
        if (s3[i] != s2[i]) {
            ok = 0;
        }
    }
    if (ok) {
        ans = min(ans, cnt);
    }
    return ans;
}

void solve() {
    int n;
    cin >> n;
    string s, T;
    cin >> s >> T;
    int n1 = 0, n2 = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
            n1++;
        }
        if (T[i] == '0') {
            n2++;
        }
    }
    if (n1 != n2) {
        cout << -1 << endl;
        return;
    }
    int z = 0, o = 0, ans = 0;
    string s1 = "", s2 = "";
    for (int i = 0; i < n; i++) {
        s1 += s[i], s2 += T[i];
        if (s[i] == T[i]) {
            continue;
        }
        if (s[i] == '0') {
            z++;
        }
        else {
            o++;
        }
        if (z == o) {
            ans += calc(s1, s2);
            z = 0, o = 0;
            s1 = "", s2 = "";
        }
    }
    cout << ans << endl;
}

int32_t main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int tt = 1; tt <= t; tt++)
    {
        //cout << "Case #" << tt << ": ";
        solve();
    }
}
