A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true:

  * Employee A is the immediate manager of employee B
  * Employee B has an immediate manager employee C such that employee A is the superior of employee C. 



The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.

Today the company is going to arrange a party. This involves dividing all n employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees A and B such that A is the superior of B.

What is the minimum number of groups that must be formed?

Input

The first line contains integer n (1 ≤ n ≤ 2000) — the number of employees.

The next n lines contain the integers pi (1 ≤ pi ≤ n or pi = -1). Every pi denotes the immediate manager for the i-th employee. If pi is -1, that means that the i-th employee does not have an immediate manager. 

It is guaranteed, that no employee will be the immediate manager of him/herself (pi ≠ i). Also, there will be no managerial cycles.

Output

Print a single integer denoting the minimum number of groups that will be formed in the party.

Examples

Input

5
-1
1
2
1
-1


Output

3

Note

For the first example, three groups are sufficient, for example: 

  * Employee 1 
  * Employees 2 and 4 
  * Employees 3 and 5 
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e) {
  cout << e << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
template <class T>
T f_min(T a, T b) {
  if (a > b)
    return b;
  else
    return a;
}
template <class T>
T f_max(T a, T b) {
  if (a > b)
    return a;
  else
    return b;
}
template <class T>
inline T sqr(T n) {
  return n * n;
}
template <class T>
T Abs(T x) {
  return (x > 0) ? x : -x;
}
template <class T>
inline double LOG(T a, T b) {
  return (log(a) / log(b));
}
template <class T>
T power(T B, T P) {
  return (P == 0) ? 1 : B * (power(B, (P - 1)));
}
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
T BigMod(T B, T P, T M) {
  if (P == 0)
    return 1;
  else if (P % 2 == 0)
    return sqr((BigMod(B, P / 2, M))) % M;
  else
    return (B % M) * (BigMod(B, P - 1, M)) % M;
}
template <class T>
T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return (a * (b / GCD(a, b)));
}
vector<int> adj[2005];
int col[2005];
vector<int> topo;
void topoSort(int x) {
  col[x] = true;
  int i;
  for (i = 0; i < (int)adj[x].size(); i++) {
    int y = adj[x][i];
    if (!col[y]) {
      topoSort(y);
      topo.push_back(y);
    }
  }
  return;
}
int depth;
void dfs(int x, int d) {
  col[x] = true;
  depth = max(depth, d);
  int i;
  int res = d;
  for (i = 0; i < (int)adj[x].size(); i++) {
    int y = adj[x][i];
    dfs(y, d + 1);
  }
  return;
}
int main(void) {
  int n;
  scanf("%d", &n);
  int i;
  for (i = 1; i <= n; i++) {
    int tag;
    scanf("%d", &tag);
    if (tag != -1) adj[tag].push_back(i);
  }
  for (i = 1; i <= n; i++) {
    if (!col[i]) {
      topoSort(i);
      topo.push_back(i);
    }
  }
  memset(col, 0, sizeof(col));
  int res = -1 << 29;
  for (i = 1; i <= n; i++) {
    if (!col[i]) {
      depth = 0;
      dfs(i, 1);
      res = max(res, depth);
    }
  }
  deb(res);
  return 0;
}
