#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MXN = 1e5 + 1;
int n, res;
int r[MXN];
int dp[MXN], pa[MXN];
vector<int> v[MXN];
void dfs(int x, int p = -1, int lvl = 1) {
  if (lvl == 1) {
    int pos = lower_bound(dp, dp + n + 1, r[x]) - dp;
    if (dp[pos - 1] < r[x] && r[x] < dp[pos]) {
      dp[pos] = r[x];
      res = max(res, pos);
    }
  }
  for (auto go : v[x]) {
    if (go == p) continue;
    int pos = lower_bound(dp, dp + n + 1, r[go]) - dp;
    int prev = dp[pos];
    if (dp[pos - 1] < r[go] && r[go] < dp[pos]) {
      dp[pos] = r[go];
      res = max(res, pos);
    }
    dfs(go, x, 1);
    dp[pos] = prev;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &r[i]);
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    dp[0] = -INF;
    for (int j = 1; j <= n; j++) dp[j] = INF;
    dfs(i);
  }
  printf("%d", res);
  return 0;
}
