#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
int a[6105], ans;
vector<int> mp[6105], vd[6105];
int d[6105], len, mlen;
void dfs(int x, int pa) {
  int whe;
  bool nw = 0;
  if (a[x] > d[len]) {
    d[++len] = a[x];
    mlen = max(len, mlen);
    vd[len].push_back(a[x]);
    whe = len;
    nw = 1;
  } else {
    int j = lower_bound(d + 1, d + len + 1, a[x]) - d;
    d[j] = a[x];
    vd[j].push_back(a[x]);
    whe = j;
  }
  for (int c : mp[x])
    if (c != pa) dfs(c, x);
  vd[whe].pop_back();
  if (nw) {
    assert(vd[whe].empty());
    d[len] = 0;
    len--;
  } else {
    assert(!vd[whe].empty());
    d[whe] = vd[whe].back();
  }
}
void cal(int rt) {
  len = 0;
  mlen = 0;
  for (int(i) = 0; (i) < (int)(n + 1); (i)++) {
    d[i] = 0;
    vd[i].clear();
  }
  dfs(rt, 0);
  ans = max(ans, mlen);
}
int main() {
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", a + i);
  for (int i = 0, u, v; i < n - 1; i++) {
    scanf("%d%d", &u, &v);
    mp[u].push_back(v);
    mp[v].push_back(u);
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) cal(i);
  printf("%d\n", ans);
  return 0;
}
