#include <bits/stdc++.h>
using namespace std;
vector<int> G[6005];
int n, ans;
int r[6005], dp[6005];
void dfs(int u, int fa) {
  int pos = lower_bound(dp + 1, dp + n + 1, r[u]) - dp;
  ans = max(ans, pos);
  int temp = dp[pos];
  dp[pos] = r[u];
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa) continue;
    dfs(v, u);
  }
  dp[pos] = temp;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &r[i]);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d %d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  memset(dp, 0x7f, sizeof(dp));
  for (int i = 1; i <= n; i++) dfs(i, -1);
  printf("%d", ans);
  return 0;
}
