#include <bits/stdc++.h>
using namespace std;
int n;
int tree[6005 * 2];
void update(int p, int value) {
  for (tree[p += n] = value; p > 1; p >>= 1)
    tree[p >> 1] = max(tree[p], tree[p ^ 1]);
}
int query(int l, int r) {
  int res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = max(res, tree[l++]);
    if (r & 1) res = max(res, tree[--r]);
  }
  return res;
}
int Ans;
int r[6005];
vector<int> all;
vector<int> adj[6005];
void dfs(int u, int p) {
  int Max = query(1, r[u]);
  int Prev = query(r[u], r[u] + 1);
  update(r[u], 1 + Max);
  Ans = max(Ans, 1 + Max);
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == p) continue;
    dfs(v, u);
  }
  update(r[u], Prev);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &r[i]);
    all.push_back(r[i]);
  }
  sort(all.begin(), all.end());
  for (int i = 1; i <= n; i++)
    r[i] = 1 + lower_bound(all.begin(), all.end(), r[i]) - all.begin();
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    memset(tree, 0, sizeof(tree));
    if (adj[i].size() == 1) dfs(i, -1);
  }
  cout << Ans << endl;
}
