#include <bits/stdc++.h>
using namespace std;
const int N = 6e3 + 5;
int n, u, v, ans;
int a[N], f[N];
int cnt, head[N];
struct edge {
  int next, to;
} e[N << 1];
inline void add(int u, int v) {
  cnt++;
  e[cnt].next = head[u];
  e[cnt].to = v;
  head[u] = cnt;
}
void dfs(int u, int fa) {
  int pos = lower_bound(f + 1, f + n + 1, a[u]) - f;
  ans = max(ans, pos);
  int now = f[pos];
  f[pos] = a[u];
  for (register int i = head[u]; i; i = e[i].next)
    if (e[i].to != fa) dfs(e[i].to, u);
  f[pos] = now;
}
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (register int i = 1; i < n; ++i)
    scanf("%d%d", &u, &v), add(u, v), add(v, u);
  for (register int i = 1; i <= n; ++i) {
    memset(f, 60, sizeof(f));
    dfs(i, 0);
  }
  printf("%d\n", ans);
  return 0;
}
