#include <bits/stdc++.h>
int first[6010], e, next[12010], v[12010];
int N, r[6010], s[6010], ans;
void add(int x, int y) {
  v[e] = y;
  next[e] = first[x], first[x] = e++;
}
void dfs(int cur, int fa, int top) {
  int pid, pv;
  if (top == 0) {
    pid = 0, pv = s[0];
    s[top++] = r[cur];
  } else if (r[cur] > s[top - 1]) {
    pid = top, pv = s[top];
    s[top++] = r[cur];
  } else {
    int min = -1, mid, max = top - 1;
    for (;;) {
      mid = (max - min + 1) / 2 + min;
      if (mid == max) {
        break;
      }
      if (s[mid] >= r[cur]) {
        max = mid;
      } else {
        min = mid;
      }
    }
    pid = mid, pv = s[mid];
    s[mid] = r[cur];
  }
  if (top > ans) {
    ans = top;
  }
  for (int i = first[cur]; i != -1; i = next[i]) {
    if (v[i] != fa) {
      dfs(v[i], cur, top);
    }
  }
  s[pid] = pv;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &r[i]);
  }
  memset(first, -1, sizeof(first)), e = 0;
  int x, y;
  for (int i = 1; i < N; i++) {
    scanf("%d%d", &x, &y);
    add(x, y), add(y, x);
  }
  ans = 1;
  for (int i = 1; i <= N; i++) {
    dfs(i, -1, 0);
  }
  printf("%d\n", ans);
  return 0;
}
