#include <bits/stdc++.h>
using namespace std;
const int MaxN = 6003;
const int INF = 0x7f7f7f7f;
int n, r[MaxN];
vector<int> e[MaxN];
int ans, lis[MaxN];
void dfs(int x, int u) {
  for (vector<int>::iterator i = e[x].begin(); i != e[x].end(); ++i) {
    int v = *i;
    if (v == u) continue;
    int p = lower_bound(lis, lis + n + 1, r[v]) - lis;
    ans = max(ans, p);
    int bak = lis[p];
    lis[p] = r[v];
    dfs(v, x);
    lis[p] = bak;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", r + i);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(v), e[v].push_back(u);
  }
  ans = 1;
  for (int i = 1; i <= n; ++i) {
    if (e[i].size() > 1) continue;
    memset(lis, 0x7f, sizeof lis);
    lis[0] = -1;
    lis[1] = r[i];
    dfs(i, -1);
  }
  printf("%d\n", ans);
  return 0;
}
