#include <bits/stdc++.h>
using namespace std;
const int maxx = 6010;
int n;
int r[maxx];
vector<int> g[maxx];
int a[maxx], cnt;
int ans;
bool vis[maxx];
void dfs(int u) {
  vis[u] = 1;
  bool f;
  int p, t;
  if (cnt == 0 || a[cnt - 1] < r[u]) {
    f = 1;
    a[cnt++] = r[u];
  } else {
    p = lower_bound(a, a + cnt, r[u]) - a;
    f = 0;
    t = a[p];
    a[p] = r[u];
  }
  ans = max(ans, cnt);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (!vis[v]) dfs(v);
  }
  if (f)
    cnt--;
  else
    a[p] = t;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &r[i]);
  for (int i = 1; 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(vis, 0, sizeof(vis));
    cnt = 0;
    dfs(i);
  }
  printf("%d\n", ans);
}
