#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
int max_restaurants = 0;             // Store the maximum number of restaurants visited

// Depth-First Search to compute the longest increasing path
void dfs(int node, int parent, int length) {
    // Update the global max_restaurants count
    max_restaurants = max(max_restaurants, length);
    
    // Explore all neighbors
    for (int neighbor : adj[node]) {
        if (neighbor == parent) continue;  // Skip the parent to avoid revisiting
        // If the neighbor's stars are greater, we can eat there
        if (stars[neighbor] > stars[node]) {
            dfs(neighbor, node, length + 1);
        } else {
            // If not, we just move on without incrementing the dining count
            dfs(neighbor, node, 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 every city to ensure we check all possible starting points
    for (int i = 1; i <= N; i++) {
        dfs(i, -1, 1);  // Start DFS from city i, no parent (-1), starting length is 1
    }
    
    // Output the result
    cout << max_restaurants << endl;
    
    return 0;
}
