#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 4e18;
const int inf = 2e9;
const int N = 6005;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int ans, n;
vector<int> adj[N];
int dp[N];
int r[N];
void dfs(int now, int p) {
  int much = r[now];
  int pos = lower_bound(dp, dp + n, much) - dp;
  ans = max(ans, pos + 1);
  int temp = dp[pos];
  dp[pos] = much;
  int i;
  for (i = 0; i < adj[now].size(); ++i) {
    if (adj[now][i] == p) continue;
    dfs(adj[now][i], now);
  }
  dp[pos] = temp;
}
int main(void) {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d", &r[i]);
  for (i = 1; i <= n - 1; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (i = 0; i < N; ++i) dp[i] = inf;
  for (i = 1; i <= n; ++i) dfs(i, -1);
  cout << ans << endl;
  return 0;
}
