#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];
struct HashTable {
  struct Trair {
    pair<int, int> A;
    int x;
    Trair() {}
    Trair(pair<int, int> _A, int _x) : A(_A), x(_x) {}
  } data[6010 << 1];
  int head[3280820], next[6010 << 1], tot;
  void insert(pair<int, int> A, int x) {
    int now = (A.first * 6010 + A.second) % 3280820;
    data[++tot] = Trair(A, x);
    next[tot] = head[now];
    head[now] = tot;
  }
  int getData(pair<int, int> A) {
    int now = (A.first * 6010 + A.second) % 3280820;
    for (int i = head[now]; i; i = next[i]) {
      if (data[i].A == A) {
        return data[i].x;
      }
    }
    return 0;
  }
};
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);
}
int solve(int u, int v);
void dfs(int x, int fa, int& ret, int from);
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;
}
