#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 6
#endif
template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template <typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << s.substr(0, i) << " = " << x << " | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}
struct DP {
vector<int> dp;
DP() : dp({1}) {}
void extend() {
dp.push_back(dp.back());
}
int query(int i) {
return i < (int) dp.size() ? dp[dp.size() - i - 1] : 0;
}
int size() {
return (int) dp.size();
}
int& operator [] (int i) {
return dp[dp.size() - i - 1];
}
void swap(DP &other) {
dp.swap(other.dp);
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, d;
cin >> n >> d;
vector<vector<int>> adj(n);
for (int i=1; i<n; i++) {
int x;
cin >> x;
adj[x].push_back(i);
}
vector<DP> dp(n);
auto dfs = [&] (auto &self, int u) -> void {
for (int v : adj[u]) {
self(self, v);
dp[v].extend();
if (dp[u].size() < dp[v].size())
dp[u].swap(dp[v]);
vector<int> ndp(dp[v].size());
for (int j=0; j<dp[v].size(); j++)
ndp[j] = max(dp[u].query(max(d - j, j)) + dp[v][j], dp[u][j] + dp[v].query(max(d - j, j)));
for (int j=dp[v].size()-1; j>=0; j--) {
if (j + 1 < dp[v].size())
ndp[j] = max(ndp[j], ndp[j+1]);
dp[u][j] = max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bnQgaT0xOyBpPG47IGkrKykgewogICAgICAgIGludCB4OwogICAgICAgIGNpbiA+PiB4OwogICAgICAgIGFkalt4XS5wdXNoX2JhY2soaSk7CiAgICB9CgogICAgdmVjdG9yPERQPiBkcChuKTsKCiAgICBhdXRvIGRmcyA9IFsmXSAoYXV0byAmc2VsZiwgaW50IHUpIC0+IHZvaWQgewogICAgICAgIGZvciAoaW50IHYgOiBhZGpbdV0pIHsKICAgICAgICAgICAgc2VsZihzZWxmLCB2KTsKICAgICAgICAgICAgZHBbdl0uZXh0ZW5kKCk7CiAgICAgICAgICAgIGlmIChkcFt1XS5zaXplKCkgPCBkcFt2XS5zaXplKCkpCiAgICAgICAgICAgICAgICBkcFt1XS5zd2FwKGRwW3ZdKTsKICAgICAgICAgICAgdmVjdG9yPGludD4gbmRwKGRwW3ZdLnNpemUoKSk7CiAgICAgICAgICAgIGZvciAoaW50IGo9MDsgajxkcFt2XS5zaXplKCk7IGorKykKICAgICAgICAgICAgICAgIG5kcFtqXSA9IG1heChkcFt1XS5xdWVyeShtYXgoZCAtIGosIGopKSArIGRwW3ZdW2pdLCBkcFt1XVtqXSArIGRwW3ZdLnF1ZXJ5KG1heChkIC0gaiwgaikpKTsKICAgICAgICAgICAgZm9yIChpbnQgaj1kcFt2XS5zaXplKCktMTsgaj49MDsgai0tKSB7CiAgICAgICAgICAgICAgICBpZiAoaiArIDEgPCBkcFt2XS5zaXplKCkpCiAgICAgICAgICAgICAgICAgICAgbmRwW2pdID0gbWF4KG5kcFtqXSwgbmRwW2orMV0pOwogICAgICAgICAgICAgICAgZHBbdV1bal0gPSBtYXgoZHBbdV1bal0sIG5kcFtqXSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9OwoKICAgIGRmcyhkZnMsIDApOwogICAgY291dCA8PCBkcFswXVswXSA8PCAiXG4iOwoKICAgIHJldHVybiAwOwp9