#include <bits/stdc++.h>
using namespace std;
int T[2 * 10010];
vector<int> G[6010];
vector<int> S[6010];
int P[6010];
int C[6010];
map<int, int> M;
bool V[6010];
int mx;
int n = 6010;
void modify(int p, int value) {
  for (T[p += n] = value; p > 1; p >>= 1) T[p >> 1] = max(T[p], T[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, T[l++]);
    if (r & 1) res = max(res, T[--r]);
  }
  return res;
}
void dfs(int u) {
  V[u] = true;
  int val = 1 + query(0, P[u]);
  S[P[u]].push_back(val);
  modify(P[u], val);
  mx = max(mx, val);
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (!V[v]) {
      dfs(v);
    }
  }
  S[P[u]].pop_back();
  if (!S[P[u]].empty()) {
    modify(P[u], S[P[u]].back());
  } else {
    modify(P[u], 0);
  }
}
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> P[i];
    C[i] = P[i];
  }
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  sort(C + 1, C + N + 1);
  int count = 1;
  M[C[1]] = 1;
  for (int i = 2; i <= N; i++) {
    if (C[i] != C[i - 1]) {
      count++;
      M[C[i]] = count;
    }
  }
  for (int i = 1; i <= N; i++) {
    P[i] = M[P[i]];
  }
  for (int i = 1; i <= N; i++) {
    dfs(i);
    memset(V, false, sizeof V);
  }
  cout << mx << '\n';
  return 0;
}
