#include <bits/stdc++.h>
using namespace std;
vector<int> a[6003];
int n, ans = 0, r[6003], mark[6003], dp[6003];
void dfs(int x) {
  int t, k;
  mark[x] = 1;
  k = lower_bound(dp, dp + n, r[x]) - dp;
  if (k > ans) ans = k;
  t = dp[k];
  dp[k] = r[x];
  for (vector<int>::iterator it = a[x].begin(); it < a[x].end(); it++) {
    int y = *it;
    if (mark[y] == 0) {
      dfs(y);
    }
  }
  dp[k] = t;
}
int main() {
  cin >> n;
  for (int i = (1); i <= (n); i++) cin >> r[i];
  for (int i = (1); i <= (n - 1); i++) {
    int x, y;
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  for (int j = (0); j <= (n - 1); j++) {
    dp[j] = 1 << 30;
  }
  for (int i = (1); i <= (n); i++) {
    for (int j = (1); j <= (n); j++) mark[j] = 0;
    dfs(i);
  }
  cout << ans + 1;
}
