#include <bits/stdc++.h>
using namespace std;
const int N = 6e3 + 1;
const int inf = 1e9 + 7;
const long long INF = 1e18 + 7;
int n, d[6010];
vector<short> g[6010], v;
short id[1000100], t[25000];
int c[6010];
short ans = 0;
void update(int v, int tl, int tr, int pos, short x) {
  if (tl == tr)
    t[v] = x;
  else {
    int mid = (tl + tr) / 2;
    if (pos <= mid)
      update(2 * v, tl, mid, pos, x);
    else
      update(2 * v + 1, mid + 1, tr, pos, x);
    t[v] = max(t[2 * v], t[2 * v + 1]);
  }
}
short get(int v, int tl, int tr, int l, int r) {
  if (tl > r || tr < l) return 0;
  if (tl >= l && tr <= r) return t[v];
  int mid = (tl + tr) / 2;
  return max(get(2 * v, tl, mid, l, r), get(2 * v + 1, mid + 1, tr, l, r));
}
void dfs(int v, int p) {
  short cur = get(1, 1, N, 1, id[d[v]] - 1);
  short prev = get(1, 1, N, id[d[v]], id[d[v]]);
  cur++;
  if (prev < cur) update(1, 1, N, id[d[v]], cur);
  ans = max(ans, cur);
  for (int i = 0; i < int(g[v].size()); i++) {
    int to = g[v][i];
    if (to == p) continue;
    dfs(to, v);
  }
  if (prev < cur) update(1, 1, N, id[d[v]], prev);
}
int main() {
  srand(777);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", d + i);
    c[i] = d[i];
  }
  sort(c + 1, c + n + 1);
  int h = unique(c + 1, c + n + 1) - (c + 1);
  for (int i = 1; i <= h; i++) id[c[i]] = i;
  for (int i = 1, a, b; i < n; i++) {
    scanf("%d %d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (int(g[i].size()) == 1) v.push_back(i);
  }
  random_shuffle(v.begin(), v.end());
  for (int i = 0; i < min(int(v.size()), 1000); i++) {
    dfs(v[i], -1);
  }
  printf("%d", ans);
}
