#include <bits/stdc++.h>
using namespace std;
const int N = 6e3 + 7;
vector<int> G[N];
int LIS[N], dig[N], n;
int ans;
void dfs(int u, int f) {
  int pos = lower_bound(LIS, LIS + n, dig[u]) - LIS;
  int tmp = LIS[pos];
  LIS[pos] = dig[u];
  ans = max(ans, pos + 1);
  for (int _v = (0); _v < ((int)(G[u]).size()); _v++) {
    int v = G[u][_v];
    if (v == f) continue;
    dfs(v, u);
  }
  LIS[pos] = tmp;
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) scanf("%d", &dig[i]);
  for (int i = (1); i < (n); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ans = 1;
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < (n); j++) LIS[j] = 0x3f3f3f3f;
    dfs(i, -1);
  }
  cout << ans << endl;
  return 0;
}
