#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
template <class T1, class T2>
bool chmax(T1 &a, const T2 b) { return a < b ? a = b, true : false; }
template <class T1, class T2>
bool chmin(T1 &a, const T2 b) { return a > b ? a = b, true : false; }
template <class T>
istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is >> i; return is; }
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &i : v) os << i << ' '; return os; }
void _co() { cout << '\n'; }
template <class Head, class... Tail>
void _co(Head&& head, Tail&&... tail) { cout << ' ' << head; _co(forward<Tail>(tail)...); }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) { cout << head; _co(forward<Tail>(tail)...); }
void ce() { cerr << '\n'; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) { cerr << head << ' '; ce(forward<Tail>(tail)...); }
void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); }
void setp(const int n) { cout << fixed << setprecision(n); }
constexpr int64_t INF = 1000000000000000001;
constexpr int64_t MOD = 1000000007;
constexpr int64_t MOD_N = 998244353;
constexpr long double EPS = 1e-11;
const double PI = acos(-1);

struct S {
    bool f;
    ll a;

    bool operator<(const S &rhs) {
        if (a < 0 && rhs.a < 0) {
            if (f != rhs.f)
                return !f;
            else
                return a < rhs.a;
        } else if (a >= 0 && rhs.a >= 0) {
            if (f != rhs.f)
                return f;
            else
                return a < rhs.a;
        } else {
            return a < 0;
        }
    }

    S &operator+=(const S &rhs) {
        if (f)
            a -= rhs.a;
        else
            a += rhs.a;
        f ^= rhs.f;
        return *this;
    }
};

int main(void) {
    ll n;
    cin >> n;
    Vec p(n - 1);
    cin >> p;
    rep(i, n - 1) p[i]--;
    Vec2<ll> c(n);
    rep(i, n - 1) c[p[i]].push_back(i + 1);

    auto dfs = [&](auto self, ll r) -> S {
        S res = S{false, 0};
        res.a++;
        vector<S> s;
        for (auto i : c[r]) {
            s.push_back(self(self, i));
        }
        sort(all(s));
        for (auto i : s) res += i;
        res.f ^= true;
        return res;
    };

    auto ans = dfs(dfs, 0);
    co((n + ans.a) / 2);

    return 0;
}
#include<bits/stdc++.h>
using namespace std;

#define fl(n)             for(long long int i=0;i<n;i++)
#define sz(a)             int((a).size())
#define tr(c,i)           for(auto i = (c).begin(); i != (c).end(); i++)
#define trr(c,i)          for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define present(c,x)      ((c).find(x) != (c).end())
#define cpresent(c,x)     (find(all(c),x) != (c).end())
#define vi                vector <int>
#define vvi               vector < vi >
#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define ll                long long
#define fr                first
#define sc                second
#define vc                vector
#define pii               pair<ll,ll>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define M                 ((long long)(1000000007))

bool inrange(pii p1, pii p2)
{
	if(p1.fr+p1.sc==p2.fr+p2.sc)
		return true;
	if(p1.fr-p1.sc==p2.fr-p2.sc)
		return true;
	if(abs(p1.fr-p2.fr)+abs(p1.sc-p2.sc)<=3)
		return true;
	return false;
}


int solve()
{
	pii st,en;
	cin>>st.fr>>st.sc;
	cin>>en.fr>>en.sc;
	if(st==en)
		return cout<<"0\n",0;
	if(inrange(st,en))
		return cout<<"1\n",0;
	if(((st.fr+st.sc)&1)==((en.fr+en.sc)&1))
		return cout<<"2\n",0;
	for(ll i=st.fr-3;i<=st.fr+3;i++)
	{
		for(ll j=st.sc-3;j<=st.sc+3;j++)
		{
			if(abs(i-st.fr)+abs(j-st.sc)>3)
				continue;
			if(inrange(en,{i,j}))
			{
				return cout<<"2\n",0;
			}
		}
	}
	cout<<"3\n",0;
	return 0;
}


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL); 

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

  int t=1;
  //cin>>t;
  while(t--)
  {
  	solve();
  }
  return 0;

}