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 
import java.util.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;

public class Main
{

  public static void main(String[] args)
  {
    long startTime = System.nanoTime();
    int n=in.nextInt();
    Graph<Integer> g=new Graph<Integer>();
    ArrayList<Integer> s=new ArrayList<Integer>();
    for(int i=1;i<=n;i++)
    {
        int b=in.nextInt();
        if(b==-1)
        {
            s.add(i);
        }
        else
        {
        g.addEdge(b,i,1);
        }
    }
   // g.printGraph(g.adjacencyMatrix);
    for(int a:s)
    {
        g.BFS(a);
    }
    
    Map<Integer,Integer> hm=new HashMap<Integer,Integer>();
    for(int i=1;i<=n;i++)
    {
        Integer t=hm.get(g.distance.get(i));
        hm.put(g.distance.get(i),t==null ? 1 : t+1);
    }
    //out.println(g.adjacencyMatrix);
    out.println(hm.size());
    long endTime = System.nanoTime();
    err.println("Execution Time : +" + (endTime-startTime)/1000000 + " milli secs");
    exit(0);
  }

static class Graph<T>
    {
      Map<T,ArrayList<T>> adjacencyList;
      Map<T,HashMap<T,Integer>> adjacencyMatrix;
      Map<T,Integer> inDegree;
      Map<T,Integer> outDegree;
      Map<T,Integer> label;
      Map<T,Boolean> visited;
      Map<T,Integer> distance;
      Map<T,T> predecessor;
      boolean isBipartite=true;
      Integer diameter;
      LinkedList<T> topologicalSorted;
      public Graph()
      {
        adjacencyList=new HashMap<T,ArrayList<T>>();
        adjacencyMatrix=new HashMap<T,HashMap<T,Integer>>();
        inDegree=new HashMap<T,Integer>();
        outDegree=new HashMap<T,Integer>();
        visited=new HashMap<T,Boolean>();
        distance=new HashMap<T,Integer>();
        predecessor=new HashMap<T,T>();
        label=new HashMap<T,Integer>();
        diameter=0;
        topologicalSorted=new LinkedList<T>();
      }

      public void resetTraversals()
      {
        visited=new HashMap<T,Boolean>();
        distance=new HashMap<T,Integer>();
        predecessor=new HashMap<T,T>();
        label=new HashMap<T,Integer>();
      }

      public void printGraph(Map<T,HashMap<T,Integer>> adjacencyMatrix)
      {
        out.print("{");
        for(T k:adjacencyMatrix.keySet())
        {
          out.print(k + ":[");
          for(T l:adjacencyMatrix.get(k).keySet())
          {
            out.print(l  + ",");
          }
          out.print( "],");
          }
        out.println("}");
      }

      public void addEdge(T i,T j,Integer w)
      {
        ArrayList<T> temp=adjacencyList.get(i);
        if(temp==null)
        {
          temp = new ArrayList<T> ();
          temp.add(j);
        }
        else
        {
          temp.add(j);
        }
        adjacencyList.put(i,temp);
        HashMap<T,Integer> hm=adjacencyMatrix.get(i);
        if(hm==null)
        {
          hm=new HashMap<T,Integer>();
          hm.put(j,w);
        }
        else
        {
          hm.put(j,w);
        }
        adjacencyMatrix.put(i,hm);
      }

    public void BFS(T source)
    {
      Queue<T> Q=new LinkedList<T>();
      visited.put(source,true);
      if(distance.get(source)==null) distance.put(source,0);
      label.put(source,0);
      predecessor.put(source,null);
      Q.add(source);
      while(Q.size()>0)
      {
        T x=Q.poll();
        ArrayList<T> adjEdges=adjacencyList.get(x);
        if(adjEdges!=null)
        {
          for(T y:adjEdges)
          {
            if(visited.get(y)!=null && visited.get(y) && label.get(y)==label.get(x))
            {
              isBipartite=false;
            }
            if(visited.get(y)==null || !visited.get(y))
            {
              visited.put(y,true);
              distance.put(y,distance.get(x)+adjacencyMatrix.get(x).get(y));
              diameter=Math.max(diameter,distance.get(y));
              predecessor.put(y,x);
              Q.add(y);
              label.put(y,~label.get(x));
            }
          }
        }
      }
    }

}



  

  static class InputReader
  {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble(){
           return Double.parseDouble(next());
        }
    }


    static void exit(int a)
    {
      out.close();
      err.close();
      System.exit(a);
    }

    static InputStream inputStream = System.in;
    static OutputStream outputStream = System.out;
    static OutputStream errStream = System.err;
    static InputReader in = new InputReader(inputStream);
    static PrintWriter out = new PrintWriter(outputStream);
    static PrintWriter err = new PrintWriter(errStream);

}
