#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
using namespace std;
typedef pair<int, int> P;
int k, a[100000], dist[100000];
vector<int> v[100000];
vector<P> w;
bool b[100000];
void cal(int x, int y){
    dist[x] = y;
    b[x] = false;
    w.push_back(P(y, x));
    for(int i=0;i<v[x].size();i++){
        cal(v[x][i], y+1);
    }
}
int hin(int x, int y){
    if(b[x])return 0;
    b[x] = true;
    if(x == 0 || (a[x] == 0 && y == k-1))return 0;
    if(y == k-1)return 1;
    return hin(a[x], y+1);
}
int main() {
    int n, ans = 0;
    cin >> n >> k >> a[0];
    if(--a[0] != 0)ans++;
    for(int i=1;i<n;i++){
        cin >> a[i];
        v[--a[i]].push_back(i);
    }
    cal(0, 0);
    sort(w.begin(), w.end(), greater<P>());
    for(int i=0;i<w.size();i++){
        int p = w[i].second;
        if(!b[p]){
            ans += hin(p, 0);
        }
    }
    cout << ans << endl;
	return 0;
}

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    V<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    V< V<int> > edges(n);
    for (int i = 1; i < n; i++) edges[a[i]].emplace_back(i);
    
    int ans = 0;
    auto dfs = [&](auto && self, int i) -> int {
        int d = 0;
        for (int e: edges[i]) {
            int chd = self(self, e);
            if (chd == k && i != 0) ans++;
            else chmax(d, chd);
        }
        return d + 1;
    };
    dfs(dfs, 0);
    if (a[0] != 0) ans++;
    cout << ans << '\n';
    return 0;
}
