#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
void eras(map<int,int> &m,int x)
{
    m[x]--;
    if (!m[x])
        m.erase(x);
}
const int N=(int)3e5+100;
const int M=(int)2e6+100;
const int inf=(int)1e9+2;
#define filename ""
    vector<int> v[N];
    int h[N];
    pair<int,int> o[N];
bool sss(pair<int,int> &x,pair<int,int> &y)
{
    if (x.fi-x.se==y.fi-y.se) re x<y;
    re x.fi-x.se>y.fi-y.se;
}
void dfs(int x)
{
    h[x]=1;
    vector<pair<int,int> > vv[2];
    for(auto y:v[x])
    {
        dfs(y);
        h[x]+=h[y];
        vv[h[y]%2].pb(o[y]);
    }
    o[x]={0,0};
    if (vv[1].size()%2)
    {
        for(auto &j:vv[0])
        {
            o[x].fi+=max(j.fi,j.se);
            o[x].se+=min(j.fi,j.se);
        }
    }
    else
    {
        for(auto &j:vv[0])
        {
            o[x].fi+=j.fi;
            o[x].se+=j.se;
        }
    }
    sort(all(vv[1]),sss);
    int i;
    fo(i,vv[1].size())
    {
        if (i%2)
        {
            o[x].fi+=vv[1][i].se;
            o[x].se+=vv[1][i].fi;
        }
        else
        {
            o[x].fi+=vv[1][i].fi;
            o[x].se+=vv[1][i].se;
        }
    }
    o[x].se++;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,i;
    cin>>n;
    fo(i,n-1)
    {
        int a;
        cin>>a;
        a--;
        v[a].pb(i+1);
    }
    dfs(0);
    cout<<o[0].se;
}

///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define     FAST            ios::sync_with_stdio(0); cin.tie(0)
#define     int 	        long long
#define 	pb 	            push_back
#define     pp              pop_back
#define 	mp 	            make_pair
#define 	pi 	            2*acos(0.0)
#define     scan(i)         scanf("%lld",&i)
#define     scann(i,j)      scanf("%lld%lld",&i,&j)
#define     print(i)        printf("%lld\n",i)
#define     printt(i,j)     printf("%lld %lld\n",i,j)
#define     loop(i,n) 	    for(int i = 0 ; i <n ; i++)
#define     loopp(i,n) 	    for(int i = 1 ; i <n ; i++)
#define     rep(i,n)        for(int i=n-1;i>=0;i--)
#define     rev(v)          reverse(v.begin(),v.end())
#define     reset(a,b)      memset(a,b,sizeof(a))
#define 	vect 	        vector<int>
#define 	vec_it 	        vector<int>::reverse_iterator vi
#define     sorta(v)        sort(v.begin(),v.end())
#define     sortd(v)        sort(v.begin(),v.end(),greater<>())
#define     sorted(v)       is_sorted(v.begin(),v.end())
#define     mnv(v)          *min_element(v.begin(),v.end())
#define     mxv(v)          *max_element(v.begin(),v.end())
#define     countv(v,a)     count(v.begin(),v.end(),a)
#define     vplusa(v,a)     v.insert(v.end(),a.begin(),a.end())
#define 	mapp 	        map<int,int>
#define     rmap            map<int,int,greater<>>m
#define 	pairr 	        pair<int,int>
#define 	sett	        set<int>
#define     rset            set<int,greater<>>s
#define 	set_it 	        set<int>::reverse_iterator si
#define     map_it          map<int,int> :: reverse_iterator mi
#define     digit(n)        floor(log10(n)+1)
#define 	yes 	        cout<<"YES"<<endl
#define 	no 	            cout<<"NO"<<endl
#define 	ff 	            first
#define 	ss 	            second
#define     mx              INT_MAX
#define     lmx             LLONG_MAX
#define     mn              INT_MIN
#define     lmn             LLONG_MIN
#define     inf             0x3f3f3f3f
#define     inff            10e18
#define     GCD             __gcd(a,b)
#define     LCM             (a/GCD)*b
template <typename T> T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
int modulo (int a, int b) { return a >= 0 ? a % b : ( b - abs ( a%b ) ) % b; }

void solve()
{
   // freopen ("(input).txt" , "r",  stdin) ;
    string st,stt;
    int low=0,high=0;
    int l,r; char ch;
    int n,k,t,x,y,z,d=0,cnt=0,temp=mx,sum=0,f=0,flag=0;
    cin>>n>>k ; vect v(n) ,a ,b ; sett s ; mapp m,mm ; pairr p ;
    for(int i=0;i<=n;i++) m[i]++;
    loop(i,n) cin>>v[i];
    for(int i=0;i<n;i++)
    {
        mm[v[i]]++;
        m.erase(v[i]);
        cnt++;
        if(cnt==k)
        {
            cnt--;
            for(auto i:m)
            {
                temp=min(temp,i.ff);
                if(d==0)
                    break;
            }
            mm[v[low]]--;
            if(mm[v[low]]==0)
                m[v[low]]++;
            low++;
        }
    }
    cout<<temp<<endl;

}

main()
{
    int t;
  //  cin>>t;
  //  while(t--)
        solve();
}
