#include <bits/stdc++.h>
using namespace std;
const int N = 6001;
int ans;
int sz;
int num[N];
vector<int> a;
vector<vector<int> > adj;
void dfs(int u, int par) {
  int lo = -1, hi = sz;
  while (lo + 1 < hi) {
    int mid = (lo + hi) >> 1;
    if (num[mid] < a[u]) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  bool pop = hi == sz;
  int old = -1;
  if (pop) {
    sz++;
  } else {
    old = num[hi];
  }
  num[hi] = a[u];
  ans = max(ans, sz);
  for (int v : adj[u]) {
    if (v != par) {
      dfs(v, u);
    }
  }
  if (pop) {
    sz--;
  } else {
    num[hi] = old;
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  a = vector<int>(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  adj = vector<vector<int> >(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  ans = 0;
  for (int i = 0; i < n; i++) {
    sz = 0;
    dfs(i, -1);
  }
  cout << ans << endl;
  return 0;
}
