#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 6e3 + 5;
int a[N];
vector<vector<int> > g(N);
int ans = 0;
vector<int> lis;
void dfs(int node, int par) {
  int f = 0;
  auto it = lower_bound(lis.begin(), lis.end(), a[node]);
  int indx = it - lis.begin();
  if (it == lis.end())
    lis.push_back(a[node]);
  else
    f = *it, *it = a[node];
  ans = max(ans, (int)lis.size());
  for (int i = 0; i < g[node].size(); i++) {
    if (g[node][i] == par) continue;
    dfs(g[node][i], node);
  }
  if (!f)
    lis.pop_back();
  else
    lis[indx] = f;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i + 1];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    dfs(i, i);
    assert(lis.size() == 0);
  }
  cout << ans << endl;
  return 0;
}
