#include <bits/stdc++.h>
using namespace std;
const int N = 6005;
int n, ans, r[N], f[N];
vector<int> G[N];
void dp(int x, int fa) {
  int p = lower_bound(f, f + n, r[x]) - f;
  int tmp = f[p];
  f[p] = min(f[p], r[x]);
  ans = max(ans, p);
  for (int i = 0; i < (int)G[x].size(); ++i)
    if (G[x][i] != fa) dp(G[x][i], x);
  f[p] = tmp;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &r[i]);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  memset(f, 0x7f, sizeof(f));
  f[0] = 0;
  for (int i = 1; i <= n; ++i) dp(i, -1);
  printf("%d\n", ans);
  return 0;
}
