#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<numeric>
#include<queue>


#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long
#define MOD 1000000007

using namespace std;

int main(){

ll int N;
cin >> N;

ll int count = 0;
ll int kari;
map< ll int, ll int > ma;
for( ll int i = 2; i*i <= N; i++){
	kari = i;
	kari *= i;
	while( kari <= N && ma[kari] != 1 ){
		ma[kari]=1;
		count += 1;
		kari *= i;
	}
}

cout << N - count;
	











	return 0;

}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

#define int long long int
#define double long double

#define all(x) begin(x), end(x)
#define Done(x) cout<<x<<endl; return;
#define endl '\n'

void solve(){
	int n; cin>>n;
	int m; cin>>m;
	map<int,int>occur;
	for(int i=0;i<n;i++){
		int a; cin>>a;
		int b; cin>>b; b++;
		int c; cin>>c;
		occur[a]+=c;
		occur[b]-=c;
	}
	int ans=0;
	int curr=0;
	int last=0;
	for(auto p:occur){
		int dist=p.first-last;
		ans+=dist*min(curr,m);
		last=p.first;
		curr+=p.second;
	}
	cout<<ans<<endl;
}

int32_t main(){
	// Remove for Interactive Problems
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	solve();
	
	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
	return 0;
}