#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6003;
vector<int> adj[MAXN];
int ppl[MAXN];
int vec[MAXN], N;
int bisearch(int p) {
  int inf = 0, sup = N - 1;
  while (inf < sup) {
    int med = (sup + inf) >> 1;
    if (ppl[vec[med]] < ppl[p]) {
      inf = med + 1;
    } else {
      sup = med;
    }
  }
  return inf;
}
int vis[MAXN];
int dfs(int v) {
  vis[v] = 1;
  bool op1 = true;
  int rv, rp;
  if (N == 0 || ppl[vec[N - 1]] < ppl[v]) {
    vec[N++] = v;
  } else {
    op1 = false;
    rp = bisearch(v);
    rv = vec[rp];
    vec[rp] = v;
  }
  int res = N;
  for (int i = 0; i < int((adj[v]).size()); ++i) {
    int k = adj[v][i];
    if (vis[k]) continue;
    res = max(res, dfs(k));
  }
  if (op1) {
    N--;
  } else {
    vec[rp] = rv;
  }
  return res;
}
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; ++i) cin >> ppl[i];
    for (int i = 0; i < n; ++i) adj[i].clear();
    for (int i = 0; i < n - 1; ++i) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      memset(vis, 0, sizeof vis);
      N = 0;
      ans = max(ans, dfs(i));
    }
    cout << ans << endl;
  }
}
