#include <bits/stdc++.h>
using namespace std;
const int maxn = 6060;
int n, val[maxn], d[maxn], g[maxn], ans = 0;
vector<int> G[maxn];
void dfs(int u, int f) {
  int k = lower_bound(g + 1, g + 1 + n, val[u]) - g;
  d[u] = k;
  int t = g[k];
  g[k] = val[u];
  ans = max(ans, d[u]);
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == f) continue;
    dfs(v, u);
  }
  g[k] = t;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", val + i);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    memset(g, 0x3f, sizeof g);
    dfs(i, -1);
  }
  printf("%d\n", ans);
  return 0;
}
