#include <bits/stdc++.h>
using namespace std;
const int maxn = 6600;
int n, val[maxn];
int Adj[maxn], Size;
struct Edge {
  int to, next;
} edge[maxn * 2];
void init_edge() {
  memset(Adj, -1, sizeof(Adj));
  Size = 0;
}
void add_edge(int u, int v) {
  edge[Size].to = v;
  edge[Size].next = Adj[u];
  Adj[u] = Size++;
}
int range[maxn], rn;
int dp[maxn], ans = 1;
void dfs(int u, int fa) {
  for (int i = Adj[u]; ~i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == fa) continue;
    int oldV;
    bool oldRn = false;
    int POS = lower_bound(range, range + rn, val[v]) - range;
    oldV = range[POS];
    range[POS] = val[v];
    dp[v] = max(dp[v], POS + 1);
    if (POS == rn) {
      oldRn = true;
      rn++;
    }
    dfs(v, u);
    if (oldRn) rn--;
    range[POS] = oldV;
  }
}
int main() {
  init_edge();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", val + i);
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }
  for (int rt = 1; rt <= n; rt++) {
    rn = 0;
    range[rn++] = val[rt];
    dp[rt] = max(dp[rt], 1);
    dfs(rt, 0);
  }
  for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}
