#include <bits/stdc++.h>
using namespace std;
const int N = 6005;
int n;
int r[N];
int d[N];
int res = 0;
vector<int> g[N];
int get(int x) {
  int l = 1, m, r = n;
  while (r - l > 1) {
    m = (l + r) >> 1;
    if (d[m] <= x)
      l = m;
    else
      r = m;
  }
  if (x <= d[l]) return l;
  return r;
}
void dfs(int v, int p) {
  int uk = get(r[v]);
  int cp = d[uk];
  d[uk] = r[v];
  res = max(res, uk);
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (to == p) continue;
    dfs(to, v);
  }
  d[uk] = cp;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &r[i]);
    d[i] = 1000000000;
  }
  for (int i = 1; i <= n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) dfs(i, -1);
  printf("%d\n", res);
  return 0;
}
