#include <bits/stdc++.h>

using namespace std;

#define N 100000
#define pb push_back

int n, k, len, a[N + 5], d[N + 5], vis[N + 5], ans;
vector<int> G[N + 5];

struct Cmp {
	bool operator () (const int &a, const int &b) const {
		return d[a] < d[b];
	}
};
priority_queue<int, vector<int>, Cmp> pq;

void dfs1(int u) {
	for (int i = 0, v; i < G[u].size(); ++i) {
		v = G[u][i];
		d[v] = d[u] + 1;
		dfs1(v);
	}
}

void dfs2(int u) {
	len++;
	if (u == 1)
		return ;
	dfs2(a[u]);
}

void mark(int u) {
	vis[u] = 1;
	for (int i = 0, v; i < G[u].size(); ++i) {
		v = G[u][i];
		if (vis[v])
			continue;
		mark(v);
	}
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	dfs2(a[1]);
	for (int i = 2; i <= n; ++i)
		G[a[i]].pb(i);
	dfs1(1);
	bool flag = 1;
	for (int i = 1; i <= n; ++i)
		if (d[i] > k || (k - d[i]) % len) {
			flag = 0;
			break;
		}
	if (flag)
		ans = 0;
	else {
		if (a[1] != 1) ans = 1;
		else ans = 0;
		a[1] = 1;
		for (int i = 2; i <= n; ++i)
			pq.push(i);
		while (!pq.empty()) {
			int u = pq.top(), v; pq.pop();
			if (d[u] <= k || vis[u])
				continue;
			ans++;
			v = u;
			for (int i = 1; i <= k - 1; ++i)
				v = a[v];
			a[v] = 1;
//			printf("u:%d v:%d\n", u, v);
			mark(v);
		}
	}
	printf("%d\n", ans);
//	for (int i = 1; i <= n; ++i) printf("%d ", a[i]);
//	printf("\n");
	return 0;
}
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 1e5;
int arr[N + 5];
vector<int> lst[N + 5];
int tot = 0;
int depth[N + 5];
int n, k;

void dfs(int idx) {
	depth[idx] = 0;
	for(auto x: lst[idx]) {
		dfs(x);
		depth[idx] = max(depth[idx], depth[x] + 1);
	}
//	cout<<"IDX "<<idx<<" "<<depth[idx]<<endl;
	if(depth[idx] == k - 1 && arr[idx] != 1 && idx != 1) {
		depth[idx] = -1;
		tot++;
	}
}

void hora(int tc) {
	cin>>n>>k;
	for(int i = 1;i <= n;i++) {
		cin>>arr[i];
		if(i != 1) lst[arr[i]].PB(i);
	}
	if(arr[1] != 1) tot++;
	dfs(1);
	cout<<tot<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}


