#include <bits/stdc++.h>
using namespace std;
int r[6010];
vector<int> E[6010];
int siz[6010];
int dp[6010];
int least[6010];
bool check[6010];
int ans;
void fun(int x, int pre) {
  ans = max(ans, dp[x]);
  for (int i = 0; i < siz[x]; i++) {
    int& cur = E[x][i];
    if (cur == pre) continue;
    int fnd = lower_bound(least + 1, least + 6010, r[cur]) - least;
    dp[cur] = fnd;
    int tmp = least[fnd];
    least[fnd] = min(least[fnd], r[cur]);
    fun(cur, x);
    least[fnd] = tmp;
  }
}
int dfs(int x) {
  int re = x;
  for (int i = 0; i < siz[x]; i++) {
    if (r[E[x][i]] < r[x]) {
      re = dfs(E[x][i]);
    }
  }
  check[re] = 1;
  return re;
}
int main() {
  int n;
  while (cin >> n) {
    ans = 0;
    fill(least, least + 6010, 1000000000);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &r[i]);
    }
    int u, v;
    for (int i = 1; i < n; i++) {
      scanf("%d%d", &u, &v);
      siz[u]++;
      siz[v]++;
      E[u].push_back(v);
      E[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) dfs(i);
    for (int i = 1; i <= n; i++) {
      if (!check[i]) continue;
      dp[i] = 1;
      least[1] = r[i];
      fun(i, 0);
    }
    cout << ans << endl;
  }
  return 0;
}
