#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
int main()
{
//ifstream cin("in.txt");
int n;
cin >> n;
//cout << n << '\n';
int k;
cin >> k;
vector<vector<pair<int, int>>> al(n + 1, vector<pair<int, int>>(1));
for(int i = 2; i <= n; i++){
int boss, d;
cin >> boss >> d;
al[i][0] = {boss, d};
al[boss].push_back({i, d});
}
pair<int, int> farthestNode;
for(int i = 1; i <= k + 1; i++){
//leghosszabb ut kereses
farthestNode = {0, 0};
vector<bool> seen(n + 1);
vector<int> dD(n + 1);
for(int i = 1; i <= n; i++){
if(!seen[i]){
queue<int> q;
q.push(i);
dD[i] = 0;
seen[i] = 1;
while(!q.empty()){
int a = q.front();
q.pop();
for(int i = 0; i < al[a].size(); i++){
if(!seen[al[a][i].first] && al[al[a][i].first][0].first != 0){
seen[al[a][i].first] = 1;
dD[al[a][i].first] = dD[a] + al[a][i].second;
q.push(al[a][i].first);
if(dD[al[a][i].first] > farthestNode.second){
farthestNode.first = al[a][i].first;
farthestNode.second = dD[al[a][i].first];
}
}
}
}
}
}
int u = farthestNode.first;
int cutVal = INT_MAX;
int cutWhere;
int dU = 0;
while(al[u][0].first != 0){
if(max(dD[u] - al[u][0].second, dU) < cutVal){
cutVal = max(dD[u] - al[u][0].second, dU);
cutWhere = u;
}
dU += al[u][0].second;
u = al[u][0].first;
}
al[cutWhere][0].first = 0;
//cout << farthestNode.first << " " << farthestNode.second << '\n';
//cout << cutWhere << '\n';
}
cout << farthestNode.second << '\n';
return 0;
}