#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int inf = 1000000000;
const long long INF = ((long long)inf) * inf;
const int LIM = 6010;
int pop[LIM];
vector<int> graph[LIM];
int dp[LIM], n, maxx;
void dfs(int par, int cur) {
  int pos = lower_bound(dp + 1, dp + n + 1, pop[cur]) - (dp + 1);
  maxx = max(maxx, pos + 1);
  int pre = dp[pos + 1];
  dp[pos + 1] = pop[cur];
  for (int v : graph[cur]) {
    if (v == par) continue;
    dfs(cur, v);
  }
  dp[pos + 1] = pre;
}
int main(int argc, char const *argv[]) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &pop[i + 1]);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  for (int i = 0; i < n + 1; i++) dp[i] = inf;
  maxx = 1;
  for (int i = 1; i <= n; i++) dfs(-1, i);
  printf("%d\n", maxx);
  return 0;
}
