#include <bits/stdc++.h>
using namespace std;
const int N = 6005, inf = 1e9;
int n, ans, a[N], x, y, dp[N];
vector<int> g[N];
void dfs(int v, int pr = -1) {
  for (auto to : g[v]) {
    if (to != pr) {
      int pos = lower_bound(dp, dp + n + 1, a[to]) - dp;
      ans = max(ans, pos);
      int saved = dp[pos];
      dp[pos] = a[to];
      dfs(to, v);
      dp[pos] = saved;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i] = inf;
  }
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    dp[1] = a[i];
    dfs(i);
  }
  cout << ans;
}
