#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6010;
int v[MAXN], ans, m;
pair<int, int> rec[MAXN];
int f[MAXN];
vector<int> edg[MAXN];
void Go(int u, int fa) {
  int ps = lower_bound(f, f + m, v[u]) - f;
  rec[u] = make_pair(ps, f[ps]);
  f[ps] = v[u];
  if (ps == m) ans = max(ans, m++);
  for (__typeof(edg[u].begin()) it = edg[u].begin(); it != edg[u].end(); it++) {
    if (*it == fa) continue;
    Go(*it, u);
  }
  f[rec[u].first] = rec[u].second;
  if (rec[u].second == 0) --m;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) scanf("%d", v + i);
  for (int i = 0; i < (n - 1); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edg[u].push_back(v);
    edg[v].push_back(u);
  }
  ans = 0;
  m = 1;
  for (int i = 1; i <= n; ++i) {
    Go(i, 0);
  }
  cout << ans << endl;
  return 0;
}
