#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
//Do DEBUG OR NOT
//#define DEBUG

#ifdef DEBUG
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#else 
#define debug(...) true
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

//prototype declaration
ll pow_mod(ll n, ll k, ll m);//繰り返し二乗法 return val:(n^k)%m
ll gcd(ll a, ll b);//最大公約数 2引数
ll ngcd(vector<ll> a);
ll lcm(ll a, ll b);//最小公倍数 2引数
ll nlcm(vector<ll> numbers);
bool isPrime(ll x);//素数判定
ll digsum(ll n);//桁和
vector<ll> enum_div(ll n);//約数全列挙
ll stringcount(string s, char c);//特定文字カウント


//__________________________main__________________________

int main(){
    string N;
    cin>>N;
    if(N.size()%2==1){
        ll temp=1;
        rep(i,N.size()-1){
            temp*=10;
        }
        temp--;
        N=to_string(temp);
    }
    debug(N);
    string fowardN;
    string backN;
    fowardN=N.substr(0,N.size()/2);
    backN=N.substr(N.size()/2,N.size());
    debug(fowardN);
    debug(backN);
    ll plus=9;
    ll start=1;
    ll goal=9;
    ll ans=0;
    rep(i,N.size()/2){
        debug(start);
        debug(goal);
        ll end=goal;
        //if((N.size()/2>1)&&(i==N.size()/2-1)&&(stoi(fowardN)<10||stoi(backN)<10)) break;
        if(i==N.size()/2-1){
            for(int i=start;i<=stoll(fowardN);i++){
                debug(i);
                if(stoll(N)<stoll(to_string(i)+to_string(i))) continue;
                ans++;
            }
            end=min(end,stoll(fowardN));
            end=min(end,stoll(backN));
        }else{
            ans+=end-start+1;
        }
        
        
        debug(ans);
        goal=goal*10+9;
        start*=10;
    }
    cout<<ans<<endl;


    return 0;
}


//__________________________functions_____________Ctrl+K,Ctrl+0
//繰り返し二乗法関数
ll pow_mod(ll n, ll k, ll m){//r:(n^k)%m
    ll r=1;
    for(;k>0;k=k>>1){
        if(k&1) r=(r*n)%m;
        n = (n*n) % m;
    }
    return r;
}
//最大公約数 2引数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最大公約数 n引数
ll ngcd(vector<ll> a){
    ll res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
//最小公倍数 2引数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
//最小公倍数 n引数
ll nlcm(vector<ll> numbers) {
    ll res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}
//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}
//桁和
ll digsum(ll n) {
    ll res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}
//約数全列挙
vector<ll> enum_div(ll n){
    vector<ll> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}
//特定文字カウント
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define ull unsigned long long
#define cint const int&
#define Pi acos(-1)

const int mod = 1e9+7;
const int inf_int = 0x7fffffff;
const ll inf_ll = 0x7fffffffffffffff;
const double ept = 1e-9;

int n;
int h[100100], nx[200200], to[200200], ct;
int siz[100100];
int q[100100], cnt;

void add(cint f, cint t) {
    nx[++ct] = h[f];
    h[f] = ct;
    to[ct] = t;
}

int dfs(cint loc, cint fa) {
    int r= -111;
    int ans = -1, oth = 0;
    vector<int > d;
    for(int i=h[loc]; i; i = nx[i])
        if(to[i] != fa) {
            r = dfs(to[i], loc);
            siz[loc] += siz[to[i]];
            if(!(siz[to[i]] & 1) && r > 0) ans += r;
            else if(!(siz[to[i]] & 1) && r < 0) oth += r;
            else if((siz[to[i]] & 1)) d.push_back(r);
        }
    int nt = d.size();
    for(int i=0; i<nt; i++) q[i+1] = d[i];
    sort(q+1, q+1+nt);
    for(int i=nt; i>=1; i--)
        if(!((nt-i) & 1)) ans += q[i];
        else ans -= q[i];
    if(nt & 1) ans -= oth;
    else ans += oth;
    return ans;
}

int main() {
    cin >> n;
    int r;
    for(int i=2; i<=n; i++) {
        cin >> r;
        add(r, i);
        add(i, r);
        siz[i] = 1;
    }
    cout << (n-dfs(1, 1))/2 << endl;
    return 0;
}
/*
3
1 2
*/