#include <bits/stdc++.h>
using namespace std;
long long modpow(long long base, long long exponent, long long modulus) {
  if (base == 0 && exponent == 0) return 0;
  long long result = 1;
  while (exponent > 0) {
    if (exponent % 2 == 1) result = (result * base) % modulus;
    exponent = exponent >> 1;
    base = (base * base) % modulus;
  }
  return result;
}
int N, x, y;
vector<vector<int> > Adj(6004);
int val[6004];
bool visit[6004];
int LIS[6004];
int ans = 0;
int Max_City = 0;
void dfs(int node) {
  int flag = 0;
  visit[node] = true;
  int p = lower_bound(LIS, LIS + ans, val[node]) - LIS;
  if (p == ans) {
    ans++;
    flag = 1;
  }
  Max_City = ((Max_City) > (ans) ? Max_City : ans);
  int rev = LIS[p];
  LIS[p] = val[node];
  for (int i = (0); i < (Adj[node].size()); i++) {
    if (!visit[Adj[node][i]]) {
      dfs(Adj[node][i]);
    }
  }
  if (flag) {
    ans--;
  } else
    LIS[p] = rev;
  return;
}
inline void ReadInput(void) {
  cin >> N;
  for (int i = (1); i < (N + 1); i++) cin >> val[i];
  for (int i = (0); i < (N - 1); i++) {
    cin >> x >> y;
    Adj[x].push_back(y);
    Adj[y].push_back(x);
  }
}
inline void solve(void) {
  for (int i = (1); i < (N + 1); i++) {
    ans = 0;
    for (int i = (1); i < (N + 2); i++) {
      visit[i] = false;
      LIS[i] = 0;
    }
    dfs(i);
  }
  cout << Max_City << endl;
}
int main(int argc, const char* argv[]) {
  ios_base::sync_with_stdio(false);
  ReadInput();
  solve();
  return 0;
}
