#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 100005;

int N;
vector<int> stars(MAXN);            // Stars of each city
vector<vector<int>> adj(MAXN);       // Adjacency list for the tree
vector<int> dp(MAXN, 1);             // DP array to store the LIS ending at each city
vector<bool> visited(MAXN, false);   // Visited array for DFS

// Depth-First Search to compute the longest increasing path
void dfs(int node, int parent) {
    visited[node] = true;
    
    for (int neighbor : adj[node]) {
        if (neighbor == parent) continue;  // Skip the parent to avoid revisiting
        if (!visited[neighbor]) {
            dfs(neighbor, node);  // Recursively explore neighbors
            
            // Update the dp array if we can eat at the neighbor
            if (stars[neighbor] > stars[node]) {
                dp[neighbor] = max(dp[neighbor], dp[node] + 1);
            } else if (stars[neighbor] < stars[node]) {
                dp[node] = max(dp[node], dp[neighbor] + 1);
            }
        }
    }
}

int main() {
    cin >> N;
    
    // Input the stars of each city
    for (int i = 1; i <= N; i++) {
        cin >> stars[i];
    }
    
    // Input the roads (edges)
    for (int i = 1; i < N; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    // Start DFS from any node, here we start from city 1
    dfs(1, -1);
    
    // The result is the maximum value in the dp array
    int max_restaurants = *max_element(dp.begin() + 1, dp.begin() + N + 1);
    
    // Output the result
    cout << max_restaurants << endl;
    
    return 0;
}
