#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, next;
} e[6010 << 1];
int n, ne, head[6010];
int r[6010], d[6010];
int f[6010][6010];
void ins(int u, int v) {
  ne++;
  e[ne].to = v;
  e[ne].next = head[u];
  head[u] = ne;
}
void insert(int u, int v) {
  ins(u, v);
  ins(v, u);
}
inline int solve(int u, int v);
void dfs(int x, int fa, int& ret, int from);
inline int solve(int u, int v) {
  if (*(*(f + u) + v)) {
    return *(*(f + u) + v);
  }
  int ret = 1;
  if (d[u] == 1) {
    if (r[u] < r[v]) {
      ret = 2;
    } else {
      ret = 1;
    }
  } else {
    dfs(u, v, ret, v);
  }
  *(*(f + u) + v) = ret;
  return ret;
}
void dfs(int x, int fa, int& ret, int from) {
  if (d[x] == 1 && r[x] < r[from]) {
    ret = max(ret, 2);
  }
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) {
      continue;
    }
    if (r[x] < r[from]) {
      ret = max(ret, solve(v, x) + 1);
    }
    dfs(v, x, ret, from);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &r[i]);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    insert(u, v);
    d[u]++;
    d[v]++;
  }
  int ans = 0;
  for (int u = 1; u <= n; u++) {
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to;
      ans = max(ans, solve(u, v));
    }
  }
  printf("%d\n", ans);
  return 0;
}
