#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
int p = 998244353;
/*int p = 1000000007;*/
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_pr(s) cout << s <<endl;return 0
#define itn int

int RE() {
	vel v(3, 2);
	return v.at(4);
}
int ru(int a, int r,int p1) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2,p1);
	ans *= ans; ans %= p1;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a,int p1) {
	return ru(a, p1 - 2,p1);
}
vel dis(int mid1, vvel &way) {
	int n = way.size();
	vel dist(n, -1); dist[mid1] = 0;
	queue<int> q;
	q.push(mid1);
	while (!q.empty()) {
		int st = q.front(); q.pop();
		rep(i, way[st].size()) {
			int to = way[st][i];
			if (dist[to] == -1) {
				dist[to] = dist[st] + 1;
				q.push(to);
			}
		}
	}
	return dist;
}
pin most_far(int now, int n, vvel &way) {
	vel dist1 = dis(now, way);
	pin ans = mkp(-1, 0);
	rep(i, n) {
		if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); }
	}
	return ans;
}

int per(int &a, int b) {
	a%=b;
	if (a < 0) { a += b; }
	return a;
}
template<typename T>
V<T> uni(V<T> &v) {
	if (v.size() == 0) { return v; }
	sor(v);
	V<T> ans(1, v[0]);
	for (int i = 1; i < v.size(); i++) {
		if (v[i] != v[i - 1]) { ans.push_back(v[i]); }
	}
	v = ans;
	return v;
}
int s_gcd(int a, int b) {
	if (b == 0) { return a; }
	return s_gcd(b, a%b);
}
int gcd(int a, int b) {
	if (a < b) { swap(a, b); }
	return s_gcd(a, b);
}
int dist(vel &x, vel &u) {
	int ans = x[0] - u[0];
	rep(i, 3) { mmax(ans, x[i] - u[i]); }
	return ans;
}
vel dijkstra(V<V<pin>> &way, int st) {
	int n = way.size();
	vel dist(n, -1);
	priority_queue<pin,vector<pin>,greater<pin>> pq;
	pq.push(mkp(0,st));
	while (!pq.empty()) {
		pin fi = pq.top(); pq.pop();
		int pot = fi.second;
		if (dist[pot] == -1) {
			dist[pot] = fi.first;
			for (auto x : way[pot]) {
				pq.push(mkp(dist[pot] + x.second, x.first));
			} 
		}
	}
	return dist;
}
int BIT[140000];
int max1(int x) {
	int ans = 0;
	while (x > 0) {
		mmax(ans, BIT[x]);
		x -= (x&(-x));
	}
	return ans;
}
void update(int x, int val) {
	while (x <= 140000) {
		mmax(BIT[x], val);
		x += (x&(-x));
	}
}
void solve(int i, vel &par, vel &rank) {
	if (i == 0) { rank[i] = 0; return; }
	if (rank[i] == -1) {
		solve(par[i], par, rank);
		rank[i] = rank[par[i]] + 1;
	}
}
void color(int i, vvel &chi, veb &is_used,int dep) {
	if (!is_used[i] and dep>=0) {
		is_used[i] = true;
		for (auto x : chi[i]) {
			color(x, chi, is_used, dep - 1);
		}
	}
}
signed main() {
	int n, k; cin >> n >> k;
	int ans = 0;
	vel par(n);
	vvel chi(n);
	rep(i, n) { cin >> par[i]; par[i]--; }
	if (par[0] != 0) { ans++; par[0] = 0; }
	for (int i = 1; i < n; i++) { chi[par[i]].push_back(i); }
	vel rank(n, -1);
	rep(i, n) { solve(i, par, rank); }
	vvel list(n);
	rep(i, n) { list[rank[i]].push_back(i); }
	veb is_used(n, false);
	for (int i = n - 1; i > k; i--) {
		for (auto x : list[i]) {
			if (!is_used[x]) {
				ans++;
				int mx = x;
				rep(ind, k - 1) { mx = par[mx]; }
				color(mx, chi, is_used,k-1);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 17408