#include <bits/stdc++.h>
using namespace std;
int n, a[6005], ans, q[6005];
vector<int> G[6005];
void dfs(int x, int fa) {
  int pos = lower_bound(q + 1, q + 1 + n, a[x]) - q;
  ans = max(pos, ans);
  int now = q[pos];
  q[pos] = a[x];
  for (int i = 0; i < G[x].size(); i++) {
    int tmp = G[x][i];
    if (tmp != fa) {
      dfs(tmp, x);
    }
  }
  q[pos] = now;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  memset(q, 0x3f3f3f3f, sizeof q);
  for (int i = 1; i <= n; i++) dfs(i, 0);
  printf("%d\n", ans);
  return 0;
}
