#include <bits/stdc++.h>
using namespace std;
vector<int> v[6005];
int no[6005], dp[6005], ans, n;
bool vis[6005];
void dfs(int cur) {
  int id = lower_bound(dp, dp + n, no[cur]) - dp;
  ans = max(ans, id + 1);
  vis[cur] = true;
  int tm = dp[id];
  dp[id] = no[cur];
  for (int i = 0; i < v[cur].size(); i++) {
    if (vis[v[cur][i]] == false) dfs(v[cur][i]);
  }
  dp[id] = tm;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    dp[i] = 999999999;
    scanf("%d", &no[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    memset(vis, false, sizeof(vis));
    dfs(i);
  }
  printf("%d\n", ans);
  return 0;
}
