#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > G;
vector<int> a;
int N;
struct edge {
  int x, y;
  edge(int _x, int _y) : x(_x), y(_y) {}
  bool operator==(edge const& other) const {
    return x == other.x && y == other.y;
  }
};
namespace std {
template <>
struct hash<edge> {
  size_t operator()(edge const& e) const {
    return hash<uint64_t>()(e.x | ((uint64_t)e.y << 32));
  }
};
}  // namespace std
unordered_map<edge, int> f;
template <typename C>
void solve_iter(int u, int v, C calc) {
  for (auto x : G[u]) {
    if (x == v) continue;
    calc(x, u);
    if (u != v) solve_iter(x, u, calc);
  }
}
int solve(int u, int v) {
  edge no(u, v);
  if (f.count(no)) {
    return f[no];
  } else {
    int best = 1;
    solve_iter(u, v, [&](int x, int y) {
      if (a[x] < a[u]) best = max(best, solve(x, y) + 1);
    });
    f[no] = best;
    return best;
  }
}
int main() {
  cin >> N;
  G.resize(N + 5);
  a.push_back(99999999);
  for (int i = 1; i <= N; i++) {
    int k;
    cin >> k;
    a.push_back(k);
  }
  for (int i = 0; i < N - 1; i++) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for (int i = 1; i <= N; i++) {
    if (G[i].size() == 1) {
      G[i].push_back(0);
    }
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < G[i].size(); j++) {
      int u = i;
      int v = G[i][j];
      ans = max(ans, solve(u, v));
    }
  }
  cout << ans << endl;
  return 0;
}
