#include <bits/stdc++.h>
using namespace std;
int n, v[6005], siz, a[6005], ans;
vector<int> ve[6005];
void dfs(int x, int par) {
  bool op = false;
  int ov;
  int put = lower_bound(a + 1, a + siz + 1, v[x]) - a;
  if (put > siz) {
    siz++;
    op = true;
  }
  ov = a[put];
  a[put] = v[x];
  if (siz > ans) ans = siz;
  for (int i = 0; i < ve[x].size(); i++) {
    if (ve[x][i] != par) dfs(ve[x][i], x);
  }
  if (op)
    siz--;
  else
    a[put] = ov;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> v[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    ve[x].push_back(y);
    ve[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) a[j] = 1000000000;
    dfs(i, i);
  }
  cout << ans;
  return 0;
}
